Hidden value assigned in js lost after postback

前端 未结 3 911
温柔的废话
温柔的废话 2020-12-16 01:33

Here\'s my problem. I have a hidden field whose value I change through a javascript method. The problem is after postback the value is lost.

How can I persist the va

相关标签:
3条回答
  • 2020-12-16 02:13

    Please use

    <asp:HiddenField ID="HiddenField1" runat="server" EnableViewState="true"/>
    

    Then we will get the value after postback.

    All the properties of HiddenField are as bellow:

    <asp:HiddenField
        EnableTheming="True|False"
        EnableViewState="True|False"
        ID="string"
        OnDataBinding="DataBinding event handler"
        OnDisposed="Disposed event handler"
        OnInit="Init event handler"
        OnLoad="Load event handler"
        OnPreRender="PreRender event handler"
        OnUnload="Unload event handler"
        OnValueChanged="ValueChanged event handler"
        runat="server"
        SkinID="string"
        Value="string"
        Visible="True|False"
    />
    
    0 讨论(0)
  • 2020-12-16 02:22

    You don't need to have the hidden input run at server. You can do:

    <input type="hidden" id="HiddenInput" name="HiddenInput" value="" />
    

    Then when you post back you can access it like that:

    protected void BtnGuardar_Click(object sender, EventArgs e)
    {
        String test = Request.Form["HiddenInput"];
    }
    
    0 讨论(0)
  • 2020-12-16 02:35

    That doesn't work like that. The value is not present since the PageLoad, so won't be postbacked. Try using a TextBox with style="display:none".

    0 讨论(0)
提交回复
热议问题