ASP.NET hidden field not updated after postback

I have code in my ASP page that looks like this:

<asp:UpdatePanel runat="server" id="updatepanel1" UpdateMode="Conditional" onload="updatepanel1_Load" ChildrenAsTriggers="false"> <ContentTemplate> <asp:HiddenField id="sendingRequest" runat="server" Value="0" /> .... </ContentTemplate> </asp:UpdatePanel> 

I also have javascript on my page that does this to trigger the update of the update panel:

 var sendingRequest = document.getElementById("<%=sendingRequest.ClientID%>"); sendingRequest.value = "1"; __doPostBack('<%= updatepanel1.ClientID %>', ''); 

Everything is working fine so far, but in my updatepanel1_Load event, I am trying to set the value back to "0":

 sendingRequest.Value = "0"; 

This value is never updated or returned to 0 on the client after the postback, and I cannot understand why!

Can anyone help? Thanks

+4
source share
3 answers

If you have problems with a hidden field, you can use a TextBox instead. Hide the css text field ( display: none; ) to get similar results for the hidden field. Its not quite pretty, but its a workable solution.

+4
source

Try calling registerstartupscript or something similar from the server side. I don’t remember the name of the method, but its part of the page object. This will register any javascript that you want to execute after the client side postback.

0
source

A similar scenario was successfully executed:

http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

Make sure you follow the same steps β€” I don’t see all your code. First try with a label to make sure it is updated as a visible control. If this works, then narrow it down with a hidden value to make sure that the behavior is no different for a hidden control.

0
source

All Articles