Unable to set Masterpage Session to ContentPage

S

Sully

I know this is a basic question, but I cannot find the answer.

I have a 3 LinkButtons on the masterpage that set a session variable,
this session variable does not get relayed to the content page until
there are 2 postbacks.

MasterPage:
protected void lbtn01_Click(object sender, EventArgs e)
{
Session["BOB"] = "01";
}

protected void lbtn02_Click(object sender, EventArgs e)
{
Session["BOB"] = "02";
}

protected void lbtn03_Click(object sender, EventArgs e)
{
Session["BOB"] = "03";
}

ContentPage:
if (Session["BOB"] != null)
{
lblDisplay.Text = Session["BOB"].ToString();
}
else
{
lblDisplay.Text = "HELLO WORLD";
}

I know I probably need to use Page_Init, but I am not sure how. Any
answers or ideas would be appreciated.


Thanks in advance.
-Sully
 
M

Mr. Arnold

Sully said:
I know this is a basic question, but I cannot find the answer.

I have a 3 LinkButtons on the masterpage that set a session variable,
this session variable does not get relayed to the content page until
there are 2 postbacks.

MasterPage:
protected void lbtn01_Click(object sender, EventArgs e)
{
Session["BOB"] = "01";
}

protected void lbtn02_Click(object sender, EventArgs e)
{
Session["BOB"] = "02";
}

protected void lbtn03_Click(object sender, EventArgs e)
{
Session["BOB"] = "03";
}

ContentPage:
if (Session["BOB"] != null)
{
lblDisplay.Text = Session["BOB"].ToString();
}
else
{
lblDisplay.Text = "HELLO WORLD";
}

I know I probably need to use Page_Init, but I am not sure how. Any
answers or ideas would be appreciated.

It should be done on the Page_Load. A Master Page has a Page_Load just like
a non Master Web page.

You should also be posting to MS.Public.dotnet.framework.aspnet.
 
G

Göran Andersson

Mr. Arnold said:
It should be done on the Page_Load. A Master Page has a Page_Load just
like a non Master Web page.

Doing it in the Page_Load is too early. The click events occur after the
load event.
 

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

Top