Ozkan Koylu Ozkan Koylu - 2 years ago 274
Javascript Question

ASP.NET set hiddenfield a value in Javascript

I don't know how to set the value of a hiddenField in Javascript. Can somebody show me how to do this?


document.getElementById('hdntxtbxTaksit').value = "";


<asp:HiddenField ID="hdntxtbxTaksit" runat="server" Value="" Visible="false"> </asp:HiddenField>

error : "Unable to get value of the property \'value\': object is null or undefined"

Answer Source

Try below code with help of ClientID.

  • Asp.net server control id will be vary if you use Master page.

Note: You can avoid ID issue by setting ClientIDMode="static" page property (ASP.Net 4.0 onwards only)

 var myHidden=  document.getElementById('<%= hdntxtbxTaksit.ClientID %>');

 if(myHidden)//checking whether it is found on DOM, but not necessary
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download