473,785 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 PageIndexChange d 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 PageIndexChange d event would have considering we were attempting to change the current page).

It turns out that on the first databind the datagrids CurrentPageInde x 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 PageIndexChange d 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 CurrentPageInde x = 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 1369
Hi,

I'm not sure if this will help solve your problem but it cleared up lot of
misunderstandin gs 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 PageIndexChange d 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 PageIndexChange d event would have considering we were attempting to change the current page).

It turns out that on the first databind the datagrids CurrentPageInde x 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 PageIndexChange d 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 CurrentPageInde x = 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
21651
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
3
2651
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 and this causes control B to be created, when this is done the VIEWSTATE is lost for CONTROL B. In the EVENT that causes CONTROL B to be created I have to set
10
2283
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 disable the session state in Web.Config the VIEWSTATE variable is still maintained and stores some values. Can anyone tell what those values are for, i.e what other info is stored in VIEWSTATE other than the session ID and the control values ?
1
1771
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 properties declared on it over and above that provided by the textbox. As I understand it, part of the process to make this work is, in the property accessor's for the properties that you wish to persist you add
7
2049
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 them, or how do we get that value? I always have to set the ViewState("FirstName") = txtBox.text myself before a postback is done, otherwise, the value of ViewState("FirstName") is always empty; there doesn't seem to be a way to retrieve that...
3
4574
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 set textboxes, radio buttons, etc - that viewstate is fine. Then I have a linkbutton that does a Server.Transfer over to Page2.aspx. When I Server.Transfer back to Page1.aspx, the viewstate info is lost. I ran across another example of this last...
9
1872
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 the server to remember a variables state *without* having to go through the rigmarole of saving and loading to and from the Session state manually or similar workaround for any Types (including custom types) in exactly the same way web controls...
6
2058
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 page gets post back it gives following error Failed to load viewstate. The control tree into which viewstate is
12
1929
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
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.