Accessing the properties of a dynamically loaded control

V

Vivek Sharma

Hi There,

I have a situation where I wish to load the controls dynamically on the
basis of user role. Hence, I am using this code.
if (UserRole == "IS Administrator")

{

Control UC1 = LoadControl("../UserControls/ISJob/uctlJobGeneral.ascx");

plhISGeneral.Controls.Add(UC1);

System.Web.UI.Control UC =
Page.LoadControl("../UserControls/ISJob/uctlJobAdmin.ascx");

plhISAdmin.Controls.Add(UC);

}

else

{

System.Web.UI.Control UC1 =
Page.LoadControl("../UserControls/ISJob/uctlJobGeneral.ascx");

plhISGeneral.Controls.Add(UC1);

}



My problem is on the click of the button (which is not included within the
control) I am unable to access the properties of the user controls. How can
I access the properties?

Please help.

Vivek
 
P

Phillip Williams

Let's say that your user control is UserControls.ISJob.uctlJobGeneral then
you needed to cast the returned value from LoadControl as:
UserControls.ISJob.uctlJobGeneral UC1 = (UserControls.ISJob.uctlJobGeneral)
LoadControl("../UserControls/ISJob/uctlJobGeneral.ascx");

Then you can access the public properties of the control UC1 as normal, e.g.
uc1.ClientID;
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top