Reading a public variable from a web user control

V

Vi

Hi,
I created a web user control that works fine to display some data. Now I
want to be able to read a public int variable from the control, but I always
get the value I'm innitilizing the variable with. Meaning I can't get the
value that is set within the control.
Here's the code I use:
Control ctl1 = LoadControl("../controls/ctl1.ascx");
((MyNamespace.ControlName)ctl1).id = myInitID;
iVarFromTheControl = ((MyNamespace.ControlName)ctl1).iVarFromTheControl;
PlaceHolder1.Controls.Add(ctl1);

This code is in Page_Load and debugging step-by-step I saw that the
control's code is executed only after Page_Load has finished executing. So I
guess that's the problem, but I'm not sure how to solve it.

Thanks.
 
A

Axel Dahmen

You need to move the following line to Page_Init():
Control ctl1 = LoadControl("../controls/ctl1.ascx");

This way ASP.NET can fill that control with its PostBack value before
Page_Load() is called.

HTH,
Axel Dahmen

------------
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top