Accessing the properties of a dynamically loaded control

Discussion in 'ASP .Net Web Controls' started by Vivek Sharma, Oct 30, 2005.

  1. Vivek Sharma

    Vivek Sharma Guest

    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
     
    Vivek Sharma, Oct 30, 2005
    #1
    1. Advertising

  2. 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
    >
    >
    >
    >
     
    Phillip Williams, Oct 31, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Smith
    Replies:
    1
    Views:
    526
    Martin Dechev
    Oct 11, 2004
  2. Vivek Sharma
    Replies:
    2
    Views:
    755
    Vivek Sharma
    Oct 31, 2005
  3. =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?=

    Accessing Dynamically Loaded UserControls

    =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?=, Feb 5, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    461
    =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?=
    Feb 6, 2007
  4. Alexey Smirnov
    Replies:
    1
    Views:
    310
    Alexey Smirnov
    Mar 27, 2007
  5. ..:: Kevin ::..

    Accessing Dynamically Loaded UserControls

    ..:: Kevin ::.., Feb 5, 2007, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    157
    ..:: Kevin ::..
    Feb 6, 2007
Loading...

Share This Page