Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DataGrid rows not recreated from ViewState

Reply
Thread Tools

DataGrid rows not recreated from ViewState

 
 
dc@upsize.de
Guest
Posts: n/a
 
      09-13-2006
Hi,

I developed a Usercontrol that primarily contains a datagrid. If the
selected item of the datagrid changes, the rows would be recreated from
viewstate.

Everything works fine on a simple test page. But in our production
environment the control will be loaded via Page.LoadControl and be
nested inside a more delicate control tree. And that's the problem: in
this environment the DataGrid simply ceases to exist on a postback.

Our BuildControls() routine sits in "OnInit" of default.aspx. When I
simply move the BuildControls() call to Page_Load, then my control
works fine. But then many other of our controls start to behave freaky,
postbacks stop working. So that is not an option.

So what can I do to circumvent the problem in my usercontrol (since I
cannot rewrite all the other controls)? I thought the reason is, that
the ViewState must be loaded before the DataGrid starts creating it's
child controls. But when I try to isolate the problem and dynamically
load the control in the OnInit method of a simple project, everything
works fine, too.

I compared the ViewState of the Page_Load / OnInit versions:
identitcal. I also compared the sequence of method calls of the test
project and the production project. Seems identical, too. When I call
BuildControls() from OnInit, both projects execute these methods in the
following order:

Default.aspx.OnInit
UserControl.CreateControlCollection
UserControl.OnInit
Default.aspx.LoadViewState
UserControl.LoadViewState
Default.aspx.Page_Load
UserControl.Page_Load

I thought the problem must be that the ViewState is loaded after
UserControl.CreateControlCollection, but that's not it since the same
call order is found in the working project.

I am really stumped and very happy about any hint on this.

Regards
DC

 
Reply With Quote
 
 
 
 
dc@upsize.de
Guest
Posts: n/a
 
      09-14-2006
A new day, a new idea. I found a similar problem in another post:

http://groups.google.de/group/micros...a8f85ff9eb7ff0

Basically, by deriving from DataGrid and adding only

protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);
if (ChildControlsCreated)
CreateControlHierarchy(false);
}

I am able to circumvent the problem, I did not find adverse side
effects as of now. Appears awkward to me, though.

Maybe somebody knows a better solution or at least an explanation. I
forgot to mention that this is all about ASP.Net 1.1.

Regards
DC

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I developed a Usercontrol that primarily contains a datagrid. If the
> selected item of the datagrid changes, the rows would be recreated from
> viewstate.
>
> Everything works fine on a simple test page. But in our production
> environment the control will be loaded via Page.LoadControl and be
> nested inside a more delicate control tree. And that's the problem: in
> this environment the DataGrid simply ceases to exist on a postback.
>
> Our BuildControls() routine sits in "OnInit" of default.aspx. When I
> simply move the BuildControls() call to Page_Load, then my control
> works fine. But then many other of our controls start to behave freaky,
> postbacks stop working. So that is not an option.
>
> So what can I do to circumvent the problem in my usercontrol (since I
> cannot rewrite all the other controls)? I thought the reason is, that
> the ViewState must be loaded before the DataGrid starts creating it's
> child controls. But when I try to isolate the problem and dynamically
> load the control in the OnInit method of a simple project, everything
> works fine, too.
>
> I compared the ViewState of the Page_Load / OnInit versions:
> identitcal. I also compared the sequence of method calls of the test
> project and the production project. Seems identical, too. When I call
> BuildControls() from OnInit, both projects execute these methods in the
> following order:
>
> Default.aspx.OnInit
> UserControl.CreateControlCollection
> UserControl.OnInit
> Default.aspx.LoadViewState
> UserControl.LoadViewState
> Default.aspx.Page_Load
> UserControl.Page_Load
>
> I thought the problem must be that the ViewState is loaded after
> UserControl.CreateControlCollection, but that's not it since the same
> call order is found in the working project.
>
> I am really stumped and very happy about any hint on this.
>
> Regards
> DC


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping an object from being recreated and added to Session on page load/postback Andy B ASP .Net 1 05-23-2008 03:19 PM
Problem with viewstate when many rows in datagrid McGeeky ASP .Net 2 12-01-2005 12:38 PM
Adding rows to a Tablecontrol does not save in viewstate Allan Ebdrup ASP .Net Web Controls 2 10-05-2005 07:15 AM
Image recreated even after deletion by java. Anonymous Java 1 11-27-2004 06:15 AM
Dynamically Recreated Child Controls not Retaining View State Earl Teigrob ASP .Net Web Controls 0 10-06-2004 03:51 PM



Advertisments