Querystring - persisting viewstate?

C

Chris Ashley

My app seems to lose its viewstate completely when I modify the
querystring. Anything I can do about this?

Cheers,

Chris
 
G

Grant Merwitz

Yes, when you modify the querystring you are infact loading a new instance
of the page, and the current viewstate no longer exists.
Viewstate only exists during postback, and will not be available when the
page loads as new again.

Why are you modifying the querystring, are you trying to remember values?
What are you trying to viewstate, a datagrid, or some values to remember?

I imagine you are trying to remember variable values while viewstating your
data (like datagrids).
So, what you can do instead of changing the querystring, is session or
viewstate the variables you are trying to remember.

so if you have a string variable called StrVar, you can remember it like
this.

string StrVar = <some string value>;

to save it:
ViewState["StrVar"] = StrVar;
or
Session["StrVar"] = StrVar;

to retrieve it
StrVar = (string)ViewState["StrVar"];
or
StrVar = (string)Session["StrVar"];

HTH
 
C

Chris Ashley

Hi Grant,

Thanks for that. Basically, I have developed a simple custom server
control for 'Wizard style' panel navigation which consists of
WizardStepper and custom nested control 'Tab'. I'm implementing the
links just as standard <a href="blah.aspx?page=1">. Just curious if
this is bad practice? I guess I should be using LinkButton controls
which would then do a proper postback, but obviously I can't do
<asp:LinkButton> in the render method of my custom control.. any better
way?
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top