LoadViewState not firing

  • Thread starter Thread starter William F. Robertson, Jr.
  • Start date Start date
W

William F. Robertson, Jr.

I am having difficulty in diagnosing this problem and was throwing it out
for some other eyes.

I have derived my own Page class from System.Web.UI.Page and have overridden
the LoadViewState method. I derive all of my application pages from my own
Page.

For some reason on two of my pages the LoadViewState derived method is not
firing and thus not setting up some of my controls on the page. On the
other 240 ish pages, the LoadViewState method is running properly.

Interesting though, one time during the debugger it did LoadViewState, but
it seemed to only be a fluke because it didn't work the next time in debug
mode. ( no code changes )

What are some of the reasons that would cause the LoadViewState method to
not fire? I have checked and the postback page request is being correctly
identified as a postback. EnableViewState is also set to true.

TIA,

bill

1.1 .Net framework
 
I have turned on tracing for the page and it is listing the LoadViewState in
the trace information, but it is not calling the overridden method on this
page only.

Any ideas?

bill
 
Are you calling the Base class's LoadViewState in your override?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Hi Kevin...haven't heard from you in a while.

Here is my relevant code from my derived page:

public class SqlPage : System.Web.UI.Page
{
protected override void LoadViewState( object savedState )
{
base.LoadViewState( savedState );
_Builder = ( SqlProcedureBuilder ) ViewState[
SqlProcedureBuilder.GetGuid() ];
if ( _Builder == null )
_Builder = new SqlProcedureBuilder();

_Builder.ConnectionString = SqlConnectionString;
}
protected override object SaveViewState()
{
//if ( !Builder.IsEmpty ) ************* <---
ViewState[ SqlProcedureBuilder.GetGuid() ] = _Builder;
return base.SaveViewState();
}
}


********
When I comment the line out, the derived classes LoadViewState is called, or
when the Builder is NOT empty it works. It seems ( I am probably wrong)
that if I don't adjust the ViewState in the SaveViewState method, the
LoadViewState method will not be called on the following postback.

bill
 
Hi Bill,

I'm wondering if the SaveViewState may be erroring out, causing the
ViewState not to load. You might try putting a try/catch in there, and using
the Finally block to load the base's ViewState. It is possible that you may
be experiencing a null reference error in that method (if _Builder is null).

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

William F. Robertson said:
Hi Kevin...haven't heard from you in a while.

Here is my relevant code from my derived page:

public class SqlPage : System.Web.UI.Page
{
protected override void LoadViewState( object savedState )
{
base.LoadViewState( savedState );
_Builder = ( SqlProcedureBuilder ) ViewState[
SqlProcedureBuilder.GetGuid() ];
if ( _Builder == null )
_Builder = new SqlProcedureBuilder();

_Builder.ConnectionString = SqlConnectionString;
}
protected override object SaveViewState()
{
//if ( !Builder.IsEmpty ) ************* <---
ViewState[ SqlProcedureBuilder.GetGuid() ] = _Builder;
return base.SaveViewState();
}
}


********
When I comment the line out, the derived classes LoadViewState is called, or
when the Builder is NOT empty it works. It seems ( I am probably wrong)
that if I don't adjust the ViewState in the SaveViewState method, the
LoadViewState method will not be called on the following postback.

bill


Kevin Spencer said:
Are you calling the Base class's LoadViewState in your override?

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

my
own
 
Kevin,

I have checked through debugger and no exceptions are through and the
accessor for the Builder will check _Builder and create if null.

When I change the SaveViewState method to

ViewState["Bob"] = new object();
return base.SaveViewState();

The LoadViewState is always called.

I am leaning more and more to the LoadViewState method is not called on the
page when the page doesn't put anything into viewstate regardless if any of
the contained controls have viewstate. (which they do.)

Thanks,

bill


Kevin Spencer said:
Hi Bill,

I'm wondering if the SaveViewState may be erroring out, causing the
ViewState not to load. You might try putting a try/catch in there, and using
the Finally block to load the base's ViewState. It is possible that you may
be experiencing a null reference error in that method (if _Builder is null).

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

William F. Robertson said:
Hi Kevin...haven't heard from you in a while.

Here is my relevant code from my derived page:

public class SqlPage : System.Web.UI.Page
{
protected override void LoadViewState( object savedState )
{
base.LoadViewState( savedState );
_Builder = ( SqlProcedureBuilder ) ViewState[
SqlProcedureBuilder.GetGuid() ];
if ( _Builder == null )
_Builder = new SqlProcedureBuilder();

_Builder.ConnectionString = SqlConnectionString;
}
protected override object SaveViewState()
{
//if ( !Builder.IsEmpty ) ************* <---
ViewState[ SqlProcedureBuilder.GetGuid() ] = _Builder;
return base.SaveViewState();
}
}


********
When I comment the line out, the derived classes LoadViewState is
called,
or
when the Builder is NOT empty it works. It seems ( I am probably wrong)
that if I don't adjust the ViewState in the SaveViewState method, the
LoadViewState method will not be called on the following postback.

bill


it
out is
not LoadViewState,
but method
to
 
Back
Top