Master Page / Content Page interaction question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jpan

    Master Page / Content Page interaction question

    My master page has a drop down list of languages. When the user
    selects a new language, I would like to call a method in the currently
    loaded content page to load all the fields with text in the chosen
    language. My current approach is in the Content page to hook into the
    SelectedIndexCh ange event of the dropdown list (ID is ddlLanguage), but
    I am not receiving the event (see code below). Is there a better way
    to do this? Alternately, could I handle the event in the master page
    codebehind and call a method in the currently loaded page? There will
    be several content pages, so they would all support the method.

    Thanks in advance,
    JPan

    // Page_Load() on Content page
    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (!this.IsPostBa ck)
    {
    // all this code seems to work without a problem
    langDDL = (DropDownList) Master.FindCont rol("ddlLanguag e");
    langDDL.Selecte dIndexChanged += new
    EventHandler(la ngDDL_SelectedI ndexChanged);
    }
    }

    // Event handler - also on Content page (not being called!)
    public void langDDL_Selecte dIndexChanged(o bject sender, EventArgs
    e)
    {
    // set UI culture, change text of each control, etc.
    }

  • Eliyahu Goldin

    #2
    Re: Master Page / Content Page interaction question

    You need to subscribe the content page to the event during postbacks, not
    during the first time where the page loads.

    The correct code will be
    // Page_Load() on Content page
    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (this.IsPostBac k)
    {
    // all this code seems to work without a problem
    langDDL = (DropDownList) Master.FindCont rol("ddlLanguag e");
    langDDL.Selecte dIndexChanged += new
    EventHandler(la ngDDL_SelectedI ndexChanged);
    }
    }


    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "jpan" <jpan@pocketlea rn.comwrote in message
    news:1152496736 .905427.108280@ 75g2000cwc.goog legroups.com...
    My master page has a drop down list of languages. When the user
    selects a new language, I would like to call a method in the currently
    loaded content page to load all the fields with text in the chosen
    language. My current approach is in the Content page to hook into the
    SelectedIndexCh ange event of the dropdown list (ID is ddlLanguage), but
    I am not receiving the event (see code below). Is there a better way
    to do this? Alternately, could I handle the event in the master page
    codebehind and call a method in the currently loaded page? There will
    be several content pages, so they would all support the method.
    >
    Thanks in advance,
    JPan
    >
    // Page_Load() on Content page
    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (!this.IsPostBa ck)
    {
    // all this code seems to work without a problem
    langDDL = (DropDownList) Master.FindCont rol("ddlLanguag e");
    langDDL.Selecte dIndexChanged += new
    EventHandler(la ngDDL_SelectedI ndexChanged);
    }
    }
    >
    // Event handler - also on Content page (not being called!)
    public void langDDL_Selecte dIndexChanged(o bject sender, EventArgs
    e)
    {
    // set UI culture, change text of each control, etc.
    }
    >

    Comment

    Working...