Last post Sep 12, 2011 11:18 AM by webJose
Sep 07, 2011 03:07 PM|webJose|LINK
Ok, so this is the weirdest ever! Visual Studio 2008 Professional, ASP.net v2.0. I have a UserControl with a single control inside it: A Repeater. This repeater control called rpMain does generate the corresponding variable in the designer. The problem
appears when I want to access the repeater control from code. There is a property called Status that receives a specific status structure, and from this status structure the data source for the repeater is built (it ends up in a 2-record data source). By
the time the Status property is set, rpMain is null! And it continues to be null after calling EnsureChildControls().
What is wrong with this setup? I'll post whatever code is needed. It isn't much anyway.
Note that I overrode CreateChildControls() in order to put a breakpoint to ensure it was being called, and yes, it is called, and yes I call the base implementation of CreateChildControls().
Any input is appreciated!!
Sep 08, 2011 08:06 AM|karang|LINK
If you can post code then it will be easier to assist.
Sep 08, 2011 11:52 AM|webJose|LINK
Thanks for stopping by. Between yesterday evening and this morning, it is working. I think it was a mixture of the following:
Sep 08, 2011 09:20 PM|Decker Dong - MSFT|LINK
Between yesterday evening and this morning, it is working.
This is strange.... Have you done something to that?
And have you got some exceptions shown on the screen?
Your key codes are also welcomed.
Sep 09, 2011 11:03 AM|webJose|LINK
Hello Decker. My previous post (the one you took my quote from) explains what I did between the working, the not working, and the again back to working. In a nutshell, it appears that web.config took a part when I added an entire namespace to the controls
To answer your other question: I used to get an exception, yes, ReferenceNullException (or something like that) because the designer-provided variable rpMain was not bein populated with a new instance of the repeater added at design time. But then again,
this problem is now gone.
Sep 11, 2011 10:52 PM|Steven Cheng - MSFT|LINK
Glad to see that you've got the previous issue resolved and thanks for sharing the detailed information and walkthrough with us.
For the further viewstate related control state persistence issue, would you consider starting a new thread with the specific description there? That can help make the thread looks more clear and for other members easier to locate your new question at the first
post of the new thread.
Sep 12, 2011 11:18 AM|webJose|LINK
Yesterday I was finally able to sort out the view state issue. This link is DA BOMB!! : http://msdn.microsoft.com/en-us/library/aa479322.aspx. This walkthrough explains how controls should
be instantiated in the CreateChildControls(), and it shows how to create a routine that takes into account whether the controls are being created due to a data bind or due to a postback.
I think a sticky thread is probably in order for this link alone with a few more explanation in a few key points. I also noted that there's probably an error in the walkthrough: If the control is being reconstructed from view state,
CreateControlHierachy() uses an array of dummy objects of type
object, but the foreach() loop uses a variable of type
RssItem. I would imagine that this produces a runtime error. In my implementation, my foreach() uses a variable of type
object, and it is cast to the appropriate data type
only if data binding.