Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello,

I have an html table in my asp.net application. When a td element is clicked, I store that value in a hidden field using JavaScript.

C#
function rebind() {
            $('.window td').on('click', function () {
                var idName = this.id;
                var selectedid = idName.substring(1);
                console.log(selectedid);
                $('#hidden').val(selectedid);
             });
           }


Now, I want to reload this aspx page after this click event because I need other data to be displayed as per the td value and I also want to preserve this hidden field value after reload and I want to use it on server side (aspx.cs).

How can I achieve this?

Thanks.
Posted
Updated 4-Feb-15 2:54am

1 solution

Add runat="server" and ClientIDMode="Static" to your <input> tag:
aspx
<input id="hidden" type="hidden" runat="server" ClientIDMode="Static" />

This will make the input a server control (an System.Web.UI.HtmlControls.HtmlInputHidden), which will automatically preserve its value on postback. (You need the ClientIDMode="Static" attribute to prevent ASP.NET from changing the control's ID when it's rendered.)

To reload the page, you just need to submit the form. Depending on what controls you have on your page, you might have a javascript function called __doPostBack which will do the job. Otherwise, you'll just need to find the form element and call its submit method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900