Link to home
Start Free TrialLog in
Avatar of rwallacej
rwallacej

asked on

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

Avatar of Ramesh Srinivas
Ramesh Srinivas
Flag of United Kingdom of Great Britain and Northern Ireland image

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


Avatar of rwallacej
rwallacej

ASKER

thanks, can you give me code please
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;
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Ramesh Srinivas
Ramesh Srinivas
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank-you very much (and apologies for longtime in accepting solution)