Accesss User Control Class From Containing Page

Discussion in 'ASP .Net' started by Fred Chateau, Aug 8, 2007.

  1. Fred Chateau

    Fred Chateau Guest

    I am trying to access a user control class, for a user control that is
    loaded dynamically, from the containing page. I have been able to access Web
    controls in the user control, but so far I have been unable to expose the
    user control class itself. I'm guessing that I need to set up an interface,
    but I am not sure how to accomplish this.

    Here is the code that loads the user control:

    protected void Page_Init(object sender, EventArgs e)
    {
    UserControl bottomPanel = (UserControl) LoadControl("~/Reviews.ascx");
    bottomPanel.ID = "Reviews_ascx";
    PlaceholderUserControl.Controls.Add(bottomPanel);
    }

    ----
    Here is how I access Web controls in the user control:

    PlaceholderUserControl.Controls[0].FindControl("radReview");

    ----

    I need to set a property of the user control for data access, but this is a
    far as I've been able to go.

    --
    Regards,

    Fred Chateau
    fchateauAtComcastDotNet
    Fred Chateau, Aug 8, 2007
    #1
    1. Advertising

  2. Fred,

    Usually user controls (as well as web controls) do not expose internal
    control structure, but rather public properties/methods that allow
    manipulating them - the internal structure of the controls should not be
    known or relied upon by the consumers.


    "Fred Chateau" wrote:

    > I am trying to access a user control class, for a user control that is
    > loaded dynamically, from the containing page. I have been able to access Web
    > controls in the user control, but so far I have been unable to expose the
    > user control class itself. I'm guessing that I need to set up an interface,
    > but I am not sure how to accomplish this.
    >
    > Here is the code that loads the user control:
    >
    > protected void Page_Init(object sender, EventArgs e)
    > {
    > UserControl bottomPanel = (UserControl) LoadControl("~/Reviews.ascx");
    > bottomPanel.ID = "Reviews_ascx";
    > PlaceholderUserControl.Controls.Add(bottomPanel);
    > }
    >
    > ----
    > Here is how I access Web controls in the user control:
    >
    > PlaceholderUserControl.Controls[0].FindControl("radReview");
    >
    > ----
    >
    > I need to set a property of the user control for data access, but this is a
    > far as I've been able to go.
    >
    > --
    > Regards,
    >
    > Fred Chateau
    > fchateauAtComcastDotNet
    >
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Aug 8, 2007
    #2
    1. Advertising

  3. Fred Chateau

    Fred Chateau Guest

    That is exactly what I am trying to do. I want to expose the user control's
    internal properties as public properties of the user control class, but I do
    not know how to get a reference to the user control class from the
    containing page. I can get a reference to the Web controls in the user
    control, but after exposing public properties of the Web controls in the
    user control class, how do I get a reference to the user control class
    itself?

    --
    Regards,

    Fred Chateau
    fchateauAtComcastDotNet


    "Sergey Poberezovskiy" <> wrote
    in message news:...
    > Fred,
    >
    > Usually user controls (as well as web controls) do not expose internal
    > control structure, but rather public properties/methods that allow
    > manipulating them - the internal structure of the controls should not be
    > known or relied upon by the consumers.
    >
    >
    > "Fred Chateau" wrote:
    >
    >> I am trying to access a user control class, for a user control that is
    >> loaded dynamically, from the containing page. I have been able to access
    >> Web
    >> controls in the user control, but so far I have been unable to expose the
    >> user control class itself. I'm guessing that I need to set up an
    >> interface,
    >> but I am not sure how to accomplish this.
    >>
    >> Here is the code that loads the user control:
    >>
    >> protected void Page_Init(object sender, EventArgs e)
    >> {
    >> UserControl bottomPanel = (UserControl) LoadControl("~/Reviews.ascx");
    >> bottomPanel.ID = "Reviews_ascx";
    >> PlaceholderUserControl.Controls.Add(bottomPanel);
    >> }
    >>
    >> ----
    >> Here is how I access Web controls in the user control:
    >>
    >> PlaceholderUserControl.Controls[0].FindControl("radReview");
    >>
    >> ----
    >>
    >> I need to set a property of the user control for data access, but this is
    >> a
    >> far as I've been able to go.
    >>
    >> --
    >> Regards,
    >>
    >> Fred Chateau
    >> fchateauAtComcastDotNet
    >>
    >>
    >>
    Fred Chateau, Aug 8, 2007
    #3
  4. Fred Chateau

    Fred Chateau Guest

    I found it. I needed to add the <%@ reference control="~/ControlName.ascx"
    %> directlve to the page.

    --
    Regards,

    Fred Chateau
    fchateauAtComcastDotNet


    "Fred Chateau" <fchateau@127.0.0.1> wrote in message
    news:...
    > That is exactly what I am trying to do. I want to expose the user
    > control's internal properties as public properties of the user control
    > class, but I do not know how to get a reference to the user control class
    > from the containing page. I can get a reference to the Web controls in the
    > user control, but after exposing public properties of the Web controls in
    > the user control class, how do I get a reference to the user control class
    > itself?
    >
    > --
    > Regards,
    >
    > Fred Chateau
    > fchateauAtComcastDotNet
    >
    >
    > "Sergey Poberezovskiy" <>
    > wrote in message
    > news:...
    >> Fred,
    >>
    >> Usually user controls (as well as web controls) do not expose internal
    >> control structure, but rather public properties/methods that allow
    >> manipulating them - the internal structure of the controls should not be
    >> known or relied upon by the consumers.
    >>
    >>
    >> "Fred Chateau" wrote:
    >>
    >>> I am trying to access a user control class, for a user control that is
    >>> loaded dynamically, from the containing page. I have been able to access
    >>> Web
    >>> controls in the user control, but so far I have been unable to expose
    >>> the
    >>> user control class itself. I'm guessing that I need to set up an
    >>> interface,
    >>> but I am not sure how to accomplish this.
    >>>
    >>> Here is the code that loads the user control:
    >>>
    >>> protected void Page_Init(object sender, EventArgs e)
    >>> {
    >>> UserControl bottomPanel = (UserControl) LoadControl("~/Reviews.ascx");
    >>> bottomPanel.ID = "Reviews_ascx";
    >>> PlaceholderUserControl.Controls.Add(bottomPanel);
    >>> }
    >>>
    >>> ----
    >>> Here is how I access Web controls in the user control:
    >>>
    >>> PlaceholderUserControl.Controls[0].FindControl("radReview");
    >>>
    >>> ----
    >>>
    >>> I need to set a property of the user control for data access, but this
    >>> is a
    >>> far as I've been able to go.
    >>>
    >>> --
    >>> Regards,
    >>>
    >>> Fred Chateau
    >>> fchateauAtComcastDotNet
    >>>
    >>>
    >>>

    >
    >
    Fred Chateau, Aug 8, 2007
    #4
    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. Charlie@CBFC
    Replies:
    1
    Views:
    526
    William F. Robertson, Jr.
    Apr 26, 2005
  2. Replies:
    0
    Views:
    1,468
  3. John Smith
    Replies:
    0
    Views:
    1,000
    John Smith
    Aug 2, 2006
  4. archana
    Replies:
    2
    Views:
    300
    archana
    May 24, 2007
  5. Des

    Connecting Accesss to ASP

    Des, Jan 9, 2006, in forum: ASP General
    Replies:
    2
    Views:
    149
Loading...

Share This Page