Accessing Asp Hiddenfield In Javascript
I have been searching through here and google for a few days now, trying to figure out why I cannot get the value of a hiddenfield variable in javascript. When accessed, the value
Solution 1:
You need to set ClientIDMode if you want to make it simple:
<asp:HiddenFieldrunat="server"ClientIDMode="Static"Id="hidServer"/><scripttype="text/javascript">alert($("#hidServer").val());
</script>
Or, use the ClientID property if you don't set ClientIDMode:
<asp:HiddenFieldrunat="server"Id="hidServer"/><scripttype="text/javascript">alert($("<%= hidServer.ClientID %>").val());
</script>
Solution 2:
User controls have always been a strange issue for referencing using js and then master pages to go along with it.
For the hidden field do this:
<asp:HiddenFieldID="hdnServer"runat="server"ClientIDMode="Static" />
in the js, do this:
var serverName = document.getElementById('hdnServer').value;
Solution 3:
Try this:
var temp = $('#mytestcontrol_hdnServer').val();
Solution 4:
you need to use '
not "
like:
var serverName = document.getElementById('<%= hdnServer.ClientID %>').value;
be careful don't use "
. You have only use '
Solution 5:
You can do this:
var temp = $('#hdnServer').val();
Instead of :
var temp = document.getElementById("<%=hdnServer.ClientID%>").value;
Also change this:
var serverName = document.getElementById("<%= hdnServer.ClientID %>").value;
To this:
var serverName = $('#hdnServer').val();
Post a Comment for "Accessing Asp Hiddenfield In Javascript"