Nicole
Guest
|
Posted:
Tue Oct 18, 2005 4:51 pm Post subject:
invoke order of page_Load and Linkbutton_Click in Template f |
|
|
Hi,
This is what my program does:
I have
*Templatefile (template), with two HtmlPlaceholders (swedishPh and
englishPh)
*Usercontrol (control) with two linkbuttons (changeToEnglish and
changeToSwedish)
*SessionState["Lang"], Lang is en or sv.
When the changeToSwedish LinkButton is clicked, the Placeholder
swedishPh.Visible=true the englishPh.Visible=false and vice versa.
In template.Page_Load I check if (string)Session["Lang"] is "sv" or
"en"
The value is changed if LinkButtons are clicked:
private void changeToSwedish_Click(object sender, System.EventArgs e)
{
Session["Lang"] = "sv";
}
The problem is that when the LinkButton is clicked and the page is
reloaded, the Page_Load of the template is executed before the
changeToSwedish_Click.
That means the Session["Lang"] is not yet changed when the templates
Page_Load is executed, and the page is reloaded with the old value of
Session["Lang"] and the page is not updated until I click one of the
LinkButtons once again.
How do I solve this problem?
Best Regards,
Nicole |
|
Stefan [MSFT]
Guest
|
Posted:
Tue Oct 18, 2005 4:51 pm Post subject:
Re: invoke order of page_Load and Linkbutton_Click in Templa |
|
|
Hi Nicole,
that is by design of ASP.NET.
You should move the logic from the Page_Load event to the PreRender event.
Here it will work.
Cheers,
Stefan
--
This posting is provided "AS IS" with no warranties, and confers no rights
New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------
"Nicole" <nicole.zoger@lorensbergs.com> wrote in message
news:1129652960.874333.211390@g49g2000cwa.googlegroups.com...
| Quote: | Hi,
This is what my program does:
I have
*Templatefile (template), with two HtmlPlaceholders (swedishPh and
englishPh)
*Usercontrol (control) with two linkbuttons (changeToEnglish and
changeToSwedish)
*SessionState["Lang"], Lang is en or sv.
When the changeToSwedish LinkButton is clicked, the Placeholder
swedishPh.Visible=true the englishPh.Visible=false and vice versa.
In template.Page_Load I check if (string)Session["Lang"] is "sv" or
"en"
The value is changed if LinkButtons are clicked:
private void changeToSwedish_Click(object sender, System.EventArgs e)
{
Session["Lang"] = "sv";
}
The problem is that when the LinkButton is clicked and the page is
reloaded, the Page_Load of the template is executed before the
changeToSwedish_Click.
That means the Session["Lang"] is not yet changed when the templates
Page_Load is executed, and the page is reloaded with the old value of
Session["Lang"] and the page is not updated until I click one of the
LinkButtons once again.
How do I solve this problem?
Best Regards,
Nicole
|
|
|