开发者

How to set the value attribute of a hidden field when runat=server

开发者 https://www.devze.com 2023-03-02 13:22 出处:网络
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 acc

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消