Weird problem w/ Composite Controls, ID values, and Viewstate across postbacks#
I was having a problem with some textboxes that I was adding to my control dynamically not retaining their value across postback. These textboxes were of course the ones that I was attaching a whole bunch of code to for a lookup control I am writing, so there was a bunch of stuff going on.

In testing I added another textbox and it DID retain its viewstate w/ no problem.

More debugging and testing and whatnot. In looking at some of the tracing from the postbacks and posts, I saw that it was naming the form element for the newly added test textbox as a generic name "cntl_1" or something like that, whereas the textbox I cared about was "TextField", the ID I was assigning to it programatically. I found that you HAD to give a webcontrol an ID in code in order for it to assign ANY ID to it in the code, which kinda sucks. I really don't care what it's ID is in the HTML, but it would only assign a NAME to it, which doesn't help me in all my javascript programming.

So long story short, I was assigning the ID value of the textboxes in a method that was being called from the prerender event. I guess what was happening was that, in the page lifecycle, it was trying to load the viewstate back into the control, and b/c I hadn't hit the prerender event of course, my textbox didn't have the ID value that was expected.

I moved the ID assignment to the constructor and everything is working fine... so far.
Categories:
Tuesday, August 23, 2005 2:57:26 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

All content © 2008, Christopher May, Inc
Open Job Positions
On this page
Google Ads
This site
Calendar
<August 2005>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 1.9.6264.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: