JQuery set text value is lost after postback

后端 未结 2 1119
孤独总比滥情好
孤独总比滥情好 2021-01-22 09:39





        
相关标签:
2条回答
  • 2021-01-22 10:08

    I think that the problem could be related to the EnableViewState property for your asp.net button; It has to be 'true' for the value to be passed into the postback handler.

    I've done a little test on my side and I'm able to reproduce your problem if EnableViewState is 'false'; It works if I set it to 'true'.

    I hope it helps,

    Roger

    0 讨论(0)
  • 2021-01-22 10:09

    Use A HiddenField To Get The value after postback

    Try This

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script src="../js/jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script>
    function btnSetText_OnClientClick() {
    $("#<%= lbl1.ClientID %>").text("123");
    $('#HiddenFileldVariable').val($("#<%= lbl1.ClientID %>").text());
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lbl1" runat="server"></asp:Label>
    <asp:Button ID="btnSetText" runat="server" Text="Set Text" OnClientClick="btnSetText_OnClientClick(); return false;" />
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
     <asp:HiddenField ID="HiddenFileldVariable" runat="server" />
    </div>
    </form>
    </body>
    </html>
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
          string str1 = HiddenFileldVariable.Value;
    }
    
    0 讨论(0)
提交回复
热议问题