Java Script: How to Get asp.net hidden or input field value by java script/ j-Query.

Some time we come across situation to retrieve server side control value at client side. I means get and set server side control value by java script and jquery. As server side control has different id as assigned on server so server control Id is not same as assigned on server that’s why we can’t apply general rule to select control like document.getElementById(‘idname’).value or what ever Below I have given code which will retrieve server side control value at client side.

For retrieve and set asp.net server side control value  we use  $(“#<%=yourServerContrlId.ClientID %>”).val();

First Method for asp.net hidden field control:

$("#<%=hfNewsContBgColor.ClientID %>").val();
<asp:HiddenField id="hfNewsContBgColor"  runat="server"></asp:HiddenField>

Alternate Method for asp.net hidden field control:

$("input[id$=hfNewsContBgColor]").val()
<asp:HiddenField id="hfNewsContBgColor"  runat="server"></asp:HiddenField>

First Method for Input field control:

<input id="hfNewsContBgColor" type="hidden" runat="server" />

var ContainerBgColor = $("#<%=hfNewsContBgColor.ClientID %>").val();
alert(ContainerBgColor);

Alternate Method for input field control:

$("input[id$=hfContainerHeight]").val()

<input id="hfContainerHeight" type="hidden" value="100" runat="server" />
Advertisements

One thought on “Java Script: How to Get asp.net hidden or input field value by java script/ j-Query.

  1. Pingback: How to Parse JSON Date on client side by java script. | [Code Destination]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s