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.
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>
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(ob ject sender, EventArgs e)
{
Session["YourCheckBox"] = checkbox.SelectedIndex;
}
}
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(ob
{
Session["YourCheckBox"] = checkbox.SelectedIndex;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank-you very much (and apologies for longtime in accepting solution)
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