Hidden Input HTML control with jQuery, ASP.NET and C#

In this post you will learn use of Hidden Input HTML control <input type="hidden"....> with jQuery, also using this from ASP.NET and C#.

This control is very useful when it comes to keep some data on web page. This data may be used in any client side scripting. Make sure do not store any sensitive data in hidden input because this is completely visible in web page view-source.

Here is an example of Hidden Input control:

<input type="hidden" class="categoryName" value="Learning jQuery"/>

Set value in hidden input control using jQuery

//this will set ‘Learning jQuery’ in hidden field
$('.categoryName').val("Learning jQuery");

Get hidden input control value using jQuery

$('.categoryName').val();   //output: Learning jQuery

Now at any point if you want to set hidden field value from C#, here is a way:

<input type="hidden" class="categoryName" value="Learning jQuery" id="categoryName" runat="server"/>

I just added two new attributes in above hidden field and now I can set its value from C# this way:

protected void Page_Load(object sender, EventArgs e)
    categoryName.Value = "Learning jQuery from C#";

Hope this helps.


Popular posts from this blog

Lambda two tables and three tables inner join code samples

Migrating database from ASP.NET Identity to ASP.NET Core Identity