all groups > asp.net webcontrols > october 2005 >
You're in the

asp.net webcontrols

group:

Accessing the properties of a dynamically loaded control


Accessing the properties of a dynamically loaded control Vivek Sharma
10/30/2005 12:00:00 AM
asp.net webcontrols:
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


RE: Accessing the properties of a dynamically loaded control Phillip Williams
10/30/2005 5:01:03 PM
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;
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


[quoted text, click to view]
AddThis Social Bookmark Button