alain123
asked on
ViewState?
ViewState["Sql"] = SqlStatement;
load the form ...(dynamically)
submit button...
reload the form.....(dynamically)
string SQL =(string)ViewState["Sql"];
ASKER
how about inside a class.cs after IsPostBack...?
How do you access the ViewState from your class.cs?
ASKER
like this
string SQL;
SQL =(string)ViewState["GridSq l"];
string SQL;
SQL =(string)ViewState["GridSq
ViewState is not a part of your class, so you cannot access it like this. You have to assign it somehow
ASKER
tks, avenger.. but somehow how?
I don't know. It is not possible to compile the solution if you have just calls to ViewState from a class. You can make it like this:
using System;
using System.Web.UI;
using System.Diagnostics;
class MyClass {
public StateBag viewState = null;
...
public void SomeMethod () {
// Do something with the view state
Trace.WriteLine (this.viewState["SQL"]);
}
...
}
And in the Page_Load:
if (this.IsPostBack) {
MyClass mc = new MyClass();
mc.viewState = this.ViewState;
mc.SomeMethod();
}
else
ViewState["Sql"] = "test";
using System;
using System.Web.UI;
using System.Diagnostics;
class MyClass {
public StateBag viewState = null;
...
public void SomeMethod () {
// Do something with the view state
Trace.WriteLine (this.viewState["SQL"]);
}
...
}
And in the Page_Load:
if (this.IsPostBack) {
MyClass mc = new MyClass();
mc.viewState = this.ViewState;
mc.SomeMethod();
}
else
ViewState["Sql"] = "test";
ASKER
hello again Avenger, about this view state issue,
how come i do this on when i load my form ViewState["XMLFORM"] = XMLDocResult.InnerXml;
and on override protected void OnInit(EventArgs e)
{
InitializeComponent();
sSQL = (string)ViewState["XMLFORM "]; --> is null?
(not from inside a class, this is all on the code behnid of the same page)
how come i do this on when i load my form ViewState["XMLFORM"] = XMLDocResult.InnerXml;
and on override protected void OnInit(EventArgs e)
{
InitializeComponent();
sSQL = (string)ViewState["XMLFORM
(not from inside a class, this is all on the code behnid of the same page)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yep, that was it... thanks a lot!
if (this.IsPostBack)
Response.Output.Write (ViewState["Sql"]);
else
ViewState["Sql"] = "test";
It works fine, no problems at all.