Lost field value after postback

I have two hidden controls:

<asp:HiddenField runat="server" id="pageHeader" />
<asp:HiddenField runat="server" id="pageInformation" />

I call the following function from the main page:

show_tip(this, document.getElementById('ctl00_pageInformation').value, document.getElementById('ctl00_pageHeader').value);

and I pass the values ​​in a hidden field on the .cs page in the page load as follows:

 string message = Request.Form["pageInformation"];
 if (string.IsNullOrEmpty(message))
 {
      ((HiddenField)Master.FindControl("pageHeader")).Value = pageHeading;
      ((HiddenField)Master.FindControl("pageInformation")).Value = pageInformation;
 }

This works fine, but on the SEND page, hidden fields lose their meaning. How to save values ​​after postback?

+3
source share
2 answers

OK, this is what you do.

. JS , . JS , .

<script type="text/javascript">
        var txt1;
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_beginRequest(BeginRequestHandler);
        prm.add_endRequest(EndRequestHandler);

        function BeginRequestHandler(sender, args) {
            txt1 = $get('<%= hdntxt1.ClientID%>').value;
        }
        function EndRequestHandler(sender, args) {
            $get('<%= hdntxt1.ClientID%>').value = txt1;
        }
</script>
<asp:HiddenField runat="server" ID="hdntxt1" Value="" />

, , , , !

+2

, reset . , cheking

if(!ispostback)
{
 string message = Request.Form["pageInformation"];
 if (string.IsNullOrEmpty(message))
 {
  ((HiddenField)Master.FindControl("pageHeader")).Value = pageHeading;
  ((HiddenField)Master.FindControl("pageInformation")).Value = pageInformation;
 }

}
0

Source: https://habr.com/ru/post/1712271/


All Articles