I think you got wrong the idea of what the viewstate is for, The ViewState's purpose in life is to persist state across postbacks. and thats it.
So, to accomplish what you want to do, you have in my opinion 2 viable options:
- Session Variables
- Using Server.Transfer
Session Variables
A way to pass values across pages. you can store control values and access them in anoter webform. the problem with this is that if you store too much data in session, than it can be a real problem for your server.
Besides that you are the one that is in charge of cleaning session variables properly.
Ex(just an example you can adapt it to your needs):
- Session["XMLSTRING"] = xmlString;
-
Response.Redirect("WebForm2.aspx");
On the page load of WebForm2.aspx(or anywhere else)
you can use that session variable:
- string someOtherThing = Convert.ToString(Session["XMLSTRING"]);
Server.Transfer
Server.Transfer might be a bit more complex. you must expose values you want to other pages as properties of the page class.
So you need to add properties so you can acces them in another webform, i prefer this method since its more object oriented.
Ex:
this goes on the "WebForm1.aspx"
- public string anyValue
-
{
-
get
-
{
-
return TextBox1.Text;
-
}
-
}
-
-
void button_click(object sender, System.EventArgs e)
-
{
-
Server.Transfer("WebForm2.aspx")
-
}
-
On "WebForm2.aspx"
-
void page_load(object sender, System.EventArgs e)
-
{
-
WebForm1 webform;
-
webform=(WebForm1)Context.Handler;
-
label1.Text = webform.anyValue
-
}