473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ChildControls and ViewState

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.

Nov 19 '05 #1
1 1342
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
1
by: Simon | last post by:
Hi everyone, I have a quick question that I hope someone can help me with: I've made a user control that contains a text box and some validation functionality. This control has a few extra...
7
by: et | last post by:
I'm not sure I understand the use of the ViewState. Do I understand correctly that values of controls are automatically held in a hidden control called ViewState? If so, then why can't we get...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
9
by: Mark Broadbent | last post by:
Been a while since I've touched asp.net but one thing that always seems to fustrate me is the loss of state on variable declarations. Is there anyway (i.e. assigning an attribute etc) to instruct...
6
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
12
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.