How can i set the value of a hiddenfield when set runat= server
,using javascript?
E.g document.开发者_Go百科getElementById("<%=hiddenid.ClientID%>").value ="45"
. Value
attribute is not accessible here. How can i set that?
you have to use single quote '
instead double "
document.getElementById('<%=hiddenid.ClientID%>').value = '45';
Control's ClientID becomes set/available in the PreRender event handler, so you can use that to pass the ID to the client-side.
Additionally you can set the ClientIDMode to Static to force the ID to never change.
Your code should work, but make sure the element actually exists when you try to get it by ID. In other words, make sure that your javascript is executed after the element is created by the browser.
精彩评论