Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Accessing the properties of a dynamically loaded control

Reply
Thread Tools

Accessing the properties of a dynamically loaded control

 
 
Vivek Sharma
Guest
Posts: n/a
 
      10-30-2005
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



 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      10-31-2005
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


"Vivek Sharma" wrote:

> 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
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing the page from dynamically loaded control Alexey Smirnov ASP .Net 1 03-27-2007 12:17 PM
Accessing properties when control loaded dynamically Vivek Sharma ASP .Net 2 10-31-2005 12:25 AM
Accessing methods and properties of dynamically loaded controls Jeff Smith ASP .Net 1 10-11-2004 01:49 PM
FWD: Help: Control lost doesn't raise event after being moved to dynamically loaded user control Tonix ASP .Net 0 08-24-2004 05:26 AM
Help: Control lost doesn't raise event after being moved to dynamically loaded user control Thanh Nguyen ASP .Net 0 04-01-2004 02:23 AM



Advertisments