How can I save asp: value of HiddenField for postback?

How to save asp: value of HiddenField via postback?

+5
source share
7 answers

This has nothing to do with ViewState. The amount of form control is supported by POST. As long as the control is created early enough in the life cycle of the page, the published value will be set on the control. If you refresh the page or click on the hyperlink that executes the GET, then the value will be lost or revert to the default one created by the constructor.

Let's get back to your question, if you have one created by the constructor HiddenField(in the aspx file), it should automatically set the value for the postback. Either you change it somewhere else in your code, or you try to access the value before setting it (i.e. Before Page_Load()). If you have the generated code HiddenField, it must have the same identifier and be created before the page sets the published values, for example, to OnInit.

I would recommend you read and understand the following articles. Otherwise, you will continue to hit the walls because the life cycle of the page and ViewState are fundamental.

http://msdn.microsoft.com/en-us/library/ms972976.aspx

http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx

+14

asp: asp: UpdatePanel .

+11

EnableViewState True

+2

By default, it was created for this. There should not be a problem if you did not disable the viewstate for the control, parent control or page.

+2
source

Yes, asp:HiddenFieldit asp:UpdatePanelworks inside .

+1
source

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
         <asp:HiddenField ID="hdnFld" Value="xyz" runat="server"/>
    </ContentTemplate>
</asp:UpdatePanel>

If you change the value of hidden fields using jQuery and after that the page is refreshed, the value of hidden fields will be the new value. now access the same using jQuery.

var currentTab = $('#hdnFld').val();
-1
source

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


All Articles