Passing ID to UserControl which builds dynamic textboxes

C

Col

Hi Guys

I've been having some fun with the following, and hopefully someone
can help out:

I have a UserControl used to display customised Address Fields. The
address fields are just textboxes which are built up dynamically from
values in a table in my database.

The user control queries the database depending on an ID and then
builds these textboxes up. Now, to maintain the state of the textboxes
through postbacks, I was told to put the Dynamic code into the
Page_Init sub in the User Control. This all works fine and the fields
keep state on all my postbacks.

My problem is that I need to pass an ID to the query in the Page_Init
sub in the user control, so that query pulls out the relevant records
only. I can do this through a Public property in the usercontrol
class, but the Page_Init sub in the user control fires before i can
pass anything into it from my Page.

Does anyone know how I can pass this ID into my user control before
the Page_Init sub fires?

AFTER that failed... I moved my Dynamic Code in the User Control from
the Page_Init to the Page_Load sub and have been able to pass my ID to
the user control from my Page with success. And the state is also kept
intact. But now, when I try iterate through the "user control's"
controls to get their values, the Page isnt aware of any child
controls belonging to my Placeholder Control in the user control. I
spose its because they havent been Initialised in Page_Init. (this
part does work if the code is in Page_Init though, but then i have the
first problem mentioned)

Does anyone know what I can do to get either of these methods working?

Thanks alot
Col
 
J

Jonathan V

Have you re-initialized your user control on each post-back, sounds like
that has not happened, and have you given the dynamically added usercontrols
the same UserIDs as when they we first created.
 
V

Victor Garcia Aprea [MVP]

Hi Col,

Can you post a very short sample of the code you're using in order to better
illustrate the problem?

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
 
C

Col

Hi Jonathan

Thanks very much for getting back to me.
I figured out part of the problem lastnight.
It all comes down to the order of specific events and when they were
firing. I kept my dynamic usercontrol code in the Page_load, but when
I tried to loop through the controls (and got no child controls), I
was doing it in the Page_load of the Page itself, which fired before
the usercontrol even built up dynamic the controls. Therefor, they
didnt exist. Doh! I moved the 'looping through controls' code into any
other event which occured after the page_load and all worked fine.
If only I thought of putting the tracing on BEFORE pulling all my hair
out.

Thanks again.
Regards,
Colin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top