Page Execution Order (ViewState)

F

Frank

I'm really stumped here. I have a couple pages where I'm using a
datagrid and a custom paging solution. I store the current page, sort
column, etc in the ViewState of the page. When a column is clicked or
the pager control (custom) is clicked I load the view state to get any
current values, then build the page accordingly...

Problem:

One of my pages works fine - paging is great and the ViewState loads as
per normal. The other page with virtually the same code does not. The
View State is null when the 'pager_navigate' event fires.

I've stepped through the code (each line in fact) and basically the
order of page execution is also identical: OnInit, Pager_Navigate (on
postback)

The difference is that in the page that works the ViewState loads its
values and thus the navigation works. On the 'broken' page, the
ViewState never loads (stepped into the Pre-Render event and the
ViewState was null.

I've checked to make sure the ViewState values are being stored before
the page renders and the ViewState has a value on both pages before
rendering.

Thoughts?
 
F

Frank

Just a little more info:

When I parse the ViewState of the rendered page, the page that works
has the values stored properly in ViewState, the 'broken' page,
however, does not seem to rendering the ViewState values to the page.

Again, on the pre-render event I am able to see the value in ViewState,
in fact I Response.Write(ViewState["CurrentPage"]); and the value is
displayed on the screen.
 
G

Guest

Hi Frank,

ViewState uses hidden element in page to store data, so it’s only available
in page not crossing pages. If you need to share data in pages, SessionState
is an option.

HTH

Elton Wang
 
F

Frank

Just to clarify, this is two separate pages I'm talking about whose
behavior appears to be different. The data is contained within the
respective pages not being shared across pages.

Like I mentioned, the first page seems to store the viewstate properly
in the 'hidden' field but the second does not. Viewstate is enabled on
both pages but something weird is going on.

Thanks
 
T

Terry Burns

Its a little difficult to diagnose this with no substance. In order to be
able to do this, we would need the code here. Almost without question there
is a difference between the two pages/code behind and its just a case of
fine diagnostics to resolve it. Usually its a question of forgetting to do
something or failing to remember something is happening in the order of
events. In any case, think carefully about the firing order and map out what
is going on on a bit of paper ( probably a large bit ) and then you may have
a chance of solving it without posting the code , otherwise there is no
choice but to post your code.
 
G

Guest

Sorry I misunderstood your question.

One possible reason, maybe (just maybe), is that the broken page’s
EnableViewState to be set false. In that case, after you assign a ViewState
variable, it exists even in PreRender event, but it is not really rendered to
browser.


Elton
 
Joined
Oct 31, 2008
Messages
1
Reaction score
0
One problem I discovered with the viewstate is that when you try to access to one object whose key doesn't exist in the viewstate, then the viewstate becomes unuseable. If you always access existing objects, then you won't have the problem.

Hope this helps.


Laurent.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top