The Page Load for a control is always before the control is handed over to
Event execution....
so what is happening is that you are executing a check on your
ViewState["pdbmode"] for null and assigning it always and then
when Button A . click event is called
you assign view state... and session...
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";
once you are out... the render is called and it renders....
put the check for checking viewstate and session and to assign label values
in a seperate method call....
CheckAndLoad()
{
if (ViewState["pdbmode"] == null)
Label1.Text = "Null";
else if(ViewState["pdbmode"] == "edit")
Label1.Text = "Edit";
else if(ViewState["pdbmode"] == "create")
Label1.Text = "Create";
else
Label1.Text = "Unknown";
if (Session["pdbmode"] == null)
Label2.Text = "Null";
else if(Session["pdbmode"] == "edit")
Label2.Text = "Edit";
else if(Session["pdbmode"] == "create")
Label2.Text = "Create";
else
Label2.Text = "Unknown";
}
on Page load first check to see if its a post back... if not then you call
the method to check view state and session and assign label text
if(!Page.IsPostback)
{
CheckAndLoad();
}
from you Event handler say Button A click
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";
CheckAndLoad();
assign values... and then call the method to check viewstate and session and
assign the values to you label.
--
Regards,
HD
"Cederstrom" <lasse#Remove#@*This*cederstrom.dk> wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
Hello Group,
I have created an ASP.NET page. The page consist of the following items:
- Button A
- Button B
- UserControl
When I press Button A, I execute the following code:
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";
When I press Button B, I execute the following code:
ViewState["pdbmode"] = "create";
Session["pdbmode"] = "create";
In my UserControl PageLoad() I have the following code:
if (ViewState["pdbmode"] == null)
Label1.Text = "Null";
else if(ViewState["pdbmode"] == "edit")
Label1.Text = "Edit";
else if(ViewState["pdbmode"] == "create")
Label1.Text = "Create";
else
Label1.Text = "Unknown";
if (Session["pdbmode"] == null)
Label2.Text = "Null";
else if(Session["pdbmode"] == "edit")
Label2.Text = "Edit";
else if(Session["pdbmode"] == "create")
Label2.Text = "Create";
else
Label2.Text = "Unknown";
---
The problem is that when I press Button A, Label1 which uses ViewState
never changes away from being Null.
Label2 Changes, but I it changes too late. I press Button A, Label2 stays
"null", then I press Button A and it changes to edit.
I guess I need to do this completly different, but how?
Basically I just need my UserControl to know if ButtonA was pressed, or
ButtonB was pressed.
I hope someone can help me, please :)
- Cederström