persist dropdown list selected value across content pages of master page

Last post 05-07-2007 6:02 AM by Amanda Wang - MSFT. 2 replies.

Sort Posts:

  • persist dropdown list selected value across content pages of master page

    05-04-2007, 7:50 AM
    • Member
      point Member
    • Nitin Pawar
    • Member since 02-20-2007, 10:03 AM
    • Mumbai
    • Posts 12

    Hi All, 

    I have a dropdown control in the master page in my project. The content pages are dependent on the value selected in the dropdown control.

    The problem is if the dropdown is selected in one page do not retains it's value while navigating to other content pages 

    I need to keep the selected value persistent across the content pages. Does somebody know how to accomplished this.

     

    Thanks in advance,

    Nitin
  • Re: persist dropdown list selected value across content pages of master page

    05-04-2007, 8:30 AM
    Answer
    • All-Star
      86,754 point All-Star
    • ecbruck
    • Member since 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 9,209
    • Moderator
    Within the DropDownList.SelectedIndexChanged event, you could simply set a cookie or a Session variable to your SelectedValue. Then, within the DropDownList.DataBound event, I'd check for the existence of this cookie or Session variable, and set the DropDownList.SelectedValue accordingly.
    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

  • Re: persist dropdown list selected value across content pages of master page

    05-07-2007, 6:02 AM

    Hi  Nitin,

    If you want to accomplished it, you could define a base class BasePage that herits from Page, then make your content page inherits from it and override relate methods.

    for example :

    BasePsge .cs

    public class BasePage :Page
    {
        public virtual string SayHello()
        {
            return "This is basepage information!";
        }
    }

     

    the code behind of master page:

    BasePage currentPage = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            currentPage = Page as BasePage;
        }

        protected void CallContentMethod_Click(object sender, EventArgs e)
        {
            if (currentPage != null)
            {
                welcomeMessage.Text = currentPage.SayHello();
            }
        }

    the code behind of content page

    default.cs

    public partial class Template_Default : BasePage

        public override string SayHello()
        {
            return "This content page information!";
        }

    Hope it helps!!

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (3 items)