Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
retain checkbox checked even after next page redirect button clicked

What I have tried:

retain checkbox checked even after next page redirect button clicked
Posted
Updated 5-Oct-17 6:31am
Comments
[no name] 5-Oct-17 9:17am    
protected void Button1_Click(object sender, EventArgs e)

{
if(!IsPostBack)
{
Page.Response.Redirect("Publishingsite/Pages/Articles-Select.aspx");
}
I have tried this
Atlapure Ambrish 5-Oct-17 10:15am    
Add more details on what you are trying to achieve..

1 solution

HI,

You can save the checkbox state in a session. On the next page you can use this value.

An example using session:

YOUR PAGE 1
ASP.NET
<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>

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


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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900