本文介绍了即使在单击下一页重定向按钮后仍保留复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保留复选框



我尝试了什么:

retain checkbox checked even after next page redirect button clicked

What I have tried:

retain checkbox checked even after next page redirect button clicked

推荐答案

<body>
    <form id="form1" runat="server">
        <asp:CheckBox ID="my_check" runat="server" Text="My Check 1" />
        <br />
        <asp:Button ID="btn" runat="server" Text="Next Page" OnClick="btn_Click" />

    </form>
</body>




protected void btn_Click(object sender, EventArgs e)
{
   HttpContext.Current.Session.Add("my_check", this.my_check.Checked);
   Response.Redirect("page2.aspx");
}





你的第2页



YOUR PAGE 2

<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="my_check_2" runat="server" Text="My Check 2" />
    </div>
    </form>
</body>




protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      this.my_check_2.Checked = (bool)HttpContext.Current.Session["my_check"];
   }
}


这篇关于即使在单击下一页重定向按钮后仍保留复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 09:03