Need the clientId of a textbox inside a content control using javascript

℡╲_俬逩灬. 提交于 2019-12-01 07:34:34

问题


I have a masterpage that contains all the javascript and inside the content control, there is a link that calls a javascript function and I want to pass the id once it's rendered differently by the server.

<asp:TextBox ID="txtstart" runat="server" Width="20%"></asp:TextBox>
<a title="Pick Date from Calendar" onclick="calendarPicker('<% txtstart.ClientId %>');" href="javascript:void(0);">

However, I keep getting this error:

Property access must assign to the property or use its value.

How would I be able to accomplish this?


回答1:


Try this instead (notice the <%= in the onclick attribute):

<asp:TextBox ID="txtstart" runat="server" Width="20%" />
<a title="Pick Date from Calendar" 
   onclick="calendarPicker('<%= txtstart.ClientId %>');" 
   href="javascript:void(0);">
</a>


来源:https://stackoverflow.com/questions/3687367/need-the-clientid-of-a-textbox-inside-a-content-control-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!