Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ChildControls and ViewState

Reply
Thread Tools

ChildControls and ViewState

 
 
Graham
Guest
Posts: n/a
 
      09-06-2005
I have created a server control that reads data from an xml file and renders either a datagrid of entries from a database or group of form controls to allow editing of an individual entry from the same database. The Xml defines how the datagrid and edit form looks and what fields each displays.
The edit form display is perfect but I am having some problems with the datagrid list display.
The datagrid has sorting and pagination enabled and functions correctly when used by itself.
But when the datagrid is used with this server control it has problems with storing its data in ViewState.
At this current time I have the server control being rendered and initialized on each page_load. This is fine the first 10 rows of data is displayed along with the 'skip to page number' pager controls of the datagrid.
When I select another page (say page 2) of the datagrid it goes through these steps:
1. page Posts back to the server
2. The Page page_load function is called which calls the server controls render/init function
3. the server controls render/init function calls the datagrids databind function, populating the datagrid with data for the first page (previous page)
4. Any events are then processed, in this case the PageIndexChanged event (because the page number has changed from 1 to 2)
5. the datagrids databind function is then called again to reflect the changes made by the event calls. This gets the second group of data and populates the datagrid with it.
6. the page is then returned to the user with the second page of data showing along with the pager controls reflecting the change.

this is all how it should be, as far as I know. I ran into trouble when trying to go back to the first page of data, and the data wouldn't change and no events fired (I would have thought the PageIndexChanged event would have considering we were attempting to change the current page).

It turns out that on the first databind the datagrids CurrentPageIndex is not reading from ViewState (where the value is stored) properly, or at all so is always setting its initial value to 0 (Page 1). This then causes the PageIndexChanged event to fire properly on all pages that don't have an index of 0. But when we want to go back the first page the initial CurrentPageIndex = 0 then the new value also = 0 so no event is fired.

I hope that made sense...

Has anyone had problems similar to this that they have managed to fix?
Any help is appreciated.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SnVsaWFuIEplbGZz?=
Guest
Posts: n/a
 
      09-06-2005
Hi,

I'm not sure if this will help solve your problem but it cleared up lot of
misunderstandings for me about the role of viewstate and exactly where it
fits into the page lifecycle:

http://msdn.microsoft.com/library/de.../viewstate.asp

Hope it helps.

Julian.

"Graham" wrote:

> I have created a server control that reads data from an xml file and renders either a datagrid of entries from a database or group of form controls to allow editing of an individual entry from the same database. The Xml defines how the datagrid and edit form looks and what fields each displays.
> The edit form display is perfect but I am having some problems with the datagrid list display.
> The datagrid has sorting and pagination enabled and functions correctly when used by itself.
> But when the datagrid is used with this server control it has problems with storing its data in ViewState.
> At this current time I have the server control being rendered and initialized on each page_load. This is fine the first 10 rows of data is displayed along with the 'skip to page number' pager controls of the datagrid.
> When I select another page (say page 2) of the datagrid it goes through these steps:
> 1. page Posts back to the server
> 2. The Page page_load function is called which calls the server controls render/init function
> 3. the server controls render/init function calls the datagrids databind function, populating the datagrid with data for the first page (previous page)
> 4. Any events are then processed, in this case the PageIndexChanged event (because the page number has changed from 1 to 2)
> 5. the datagrids databind function is then called again to reflect the changes made by the event calls. This gets the second group of data and populates the datagrid with it.
> 6. the page is then returned to the user with the second page of data showing along with the pager controls reflecting the change.
>
> this is all how it should be, as far as I know. I ran into trouble when trying to go back to the first page of data, and the data wouldn't change and no events fired (I would have thought the PageIndexChanged event would have considering we were attempting to change the current page).
>
> It turns out that on the first databind the datagrids CurrentPageIndex is not reading from ViewState (where the value is stored) properly, or at all so is always setting its initial value to 0 (Page 1). This then causes the PageIndexChanged event to fire properly on all pages that don't have an index of 0. But when we want to go back the first page the initial CurrentPageIndex = 0 then the new value also = 0 so no event is fired.
>
> I hope that made sense...
>
> Has anyone had problems similar to this that they have managed to fix?
> Any help is appreciated

 
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
ChildControls state mauricio ASP .Net 1 03-11-2008 03:23 PM
Events don't fire in control with identical childcontrols Nico ASP .Net Web Controls 0 08-21-2007 08:59 AM
ChildControls disappear after Clicking Sandy ASP .Net Web Controls 0 08-12-2005 07:48 AM
Rendered control vs childcontrols Peter ASP .Net Web Controls 0 05-01-2005 11:19 AM
DataGrid childcontrols problem Richard Watt ASP .Net Building Controls 5 04-27-2004 06:23 AM



Advertisments