[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

MasterPage - save value when user goes to other page

Hi

I'd think this would be simple. I have master page with checkbox.
When user navigates away from page1 using the MasterPage to another page using the same master page I want the checkbox to remain in same checked/unchecked state as it was before they navigated away. The snippet here shows where the checkbox is on master page.


Thanks in advance for help.
<asp:UpdatePanel runat="server" ID="HeaderUpdatePanel">
                <ContentTemplate>
 
....
 
                                                <asp:CheckBox runat="server" ID="IsAutoUpdateEnabled" Checked="false" AutoPostBack="true"  />
                </ContentTemplate>

Open in new window

0
rwallacej
Asked:
rwallacej
  • 3
  • 2
1 Solution
 
Ramesh SrinivasTechnical ConsultantCommented:
Hi,

You will need to use a Session variable for this or a viewstate object to store the checkbox value and assign on each page to the checkbox.

thanks.

KS


0
 
rwallacejAuthor Commented:
thanks, can you give me code please
0
 
Ramesh SrinivasTechnical ConsultantCommented:
If you haven't already down so, set autopostback="true" and add an eventhandler for your checkbox.  Below is an example of a persistent checkbox:

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["YourCheckBox"] != null)
            {
                dropdown.SelectedIndex = (int)Session["YourDropdown"];
            }
        }
    }

    protected void dropdown_CheckedChanged(object sender, EventArgs e)
    {
        Session["YourCheckBox"] = checkbox.SelectedIndex;
    }
}
0
 
Ramesh SrinivasTechnical ConsultantCommented:
Sorry here is correct version...

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["YourCheckBox"] != null)
            {
                checkbox.SelectedIndex = (int)Session["YourDropdown"];
            }
        }
    }

    protected void dropdown_CheckedChanged(object sender, EventArgs e)
    {
        Session["YourCheckBox"] = checkbox.SelectedIndex;
    }

checkbox refers to the CheckBox control on your master page.

thanks.
0
 
rwallacejAuthor Commented:
thank-you very much (and apologies for longtime in accepting solution)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now