Master Page / Content Page interaction question

J

jpan

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
SelectedIndexChange 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(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
// all this code seems to work without a problem
langDDL = (DropDownList) Master.FindControl("ddlLanguage");
langDDL.SelectedIndexChanged += new
EventHandler(langDDL_SelectedIndexChanged);
}
}

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

Eliyahu Goldin

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(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// all this code seems to work without a problem
langDDL = (DropDownList) Master.FindControl("ddlLanguage");
langDDL.SelectedIndexChanged += new
EventHandler(langDDL_SelectedIndexChanged);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top