473,473 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CreateChildControls before LoadViewState = Bug in DataGrid and Repeater

I've found what seems to be a nasty bug in the DataGrid and Repeater
classes. If CreateChildControls gets called before LoadViewState,
ViewState fails to map and you end up with nothing on a Postback.
Please try the following test, and let me know if you can reproduce
this:

- Create a custom DataGrid or Repeater class that does nothing but
derive from one of the above and gives a place to put breakpoints in
overriden handlers
- Create a simple test case on a WebForm. I use template columns, but
BoundColumns might work as well.
- Create something in your DataGrid/Repeater that posts back, like a
LinkButton in a HeaderTemplate.
- Only DataBind if it's not a PostBack
- Put an EnsureChildControls at the beginning of OnInit in your custom
DataGrid/Repeater

When I click on the LinkButton, I get no output at all. Put
breakpoints in OnInit, LoadViewState, and CreateChildControls of your
custom class. If CreateChildControls gets called before LoadViewState,
nothing maps and there's no output. Now, if you take
EnsureChildControls out of OnInit, and your test is simple, you'll see
LoadViewState happen before CreateChildControls and everything will
work wonderfully.

Why is that? That's exactly opposite from everything I've learned so
far concerning server controls. Usually, the earlier you re-create all
your controls the better for mapping events, ViewState, etc. Why are
these framework controls different? I can't avoid having my controls
created early in my big application because I usually put
EnsureChildControls in all my Properties, etc, like I thought was good
practice. Are DataGrids and Repeaters doomed to fail with these
practices?

I've considered finding a workaround. I even considered calling
LoadViewState at the beginning of CreateChildControls on a PostBack,
but I haven't tried it yet because I don't know if it would be safe to
do it even if it's possible. Any help or input on why this is
happening or any hacks or workarounds will be very welcome.

Nov 18 '05 #1
0 1479

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

Similar topics

3
by: Jeremy Ames | last post by:
I am trying to use a datagrid to pull information from a database. I prefer to use latebinding to this. Well, I finally got my information to populate the datagrid, but the information came out in...
2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
0
by: SSW | last post by:
Hi: In aspx.cs page i had written the code below. I only have TextBox and Button Control. LoadViewStateis Never called But when we put datagrid/DataList It works. Can any one, please tell where...
2
by: SSW | last post by:
Hi: In aspx.cs page i had written the code below. I have a button control and only create TextBox Control dynamically. LoadViewState is Never called. But when we put datagrid/DataList it...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
2
by: News | last post by:
Hi I need help to display and edit data in a data grid within a repeater. The code is below: Sub dgrdEvents_EditCommand(sender As Object, e As DataGridCommandEventArgs)...
6
by: Nergal | last post by:
LoadViewState is taking a long time on a page, the bigger the dataset the longer the wait and also it takes longer on remote server than local host. EnableViewState is FALSE and when I examine...
1
by: JD | last post by:
Hello Everyone, I am trying to do a page where when the user gets to the page it will look very similar to the following: <table border=1> <tr> <td bgcolor="green" colspan="2">Main...
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
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.