Inheriting from System.Web.UI.Page and System.Web.UI.UserControl

Discussion in 'ASP .Net' started by DanG, Jan 24, 2006.

  1. DanG

    DanG Guest

    Howdy,

    On past .NET projects, I only had System.Web.UI.Page forms. One
    application needed a set of functions to do processing against the
    Page, Session and Request objects associated with the current Form. I
    handled this by making a new class (BasePage) which inherits from
    System.Web.UI.Page. Each form would then inherit from BasePage rather
    than System.Web.UI.Page.

    I am now on a project that has both System.Web.UI.Page and
    System.Web.UI.UserControl forms. I want to do the same type of
    BasePage processing for the UserControl screens, but I can't inherit
    them from BasePage. Currently, I made two classes that are identical,
    except that each inherit from the respective System.Web.UI object.
    Obviously, I would like a single class that would handle both types of
    forms, but I can't figure out the proper way to do it. I could use a
    clue.

    Thanks
    Dan
    DanG, Jan 24, 2006
    #1
    1. Advertising

  2. UserControl is not page. So you cannot inherit your usercontrols from your
    BasePage. In my understanding, what you want is to use functions in your
    BasePage from those usercontrols. One way you can do is to cast use
    usercontrol's contaniner page to BasePage. The use its functions:

    BasePage parentPage = (BasePage)this.Page; // C#

    Or

    Dim parentPage As BasePage = CType(Me.Page, BasePage) ' VB.NET


    HTH

    Elton Wang
    "DanG" wrote:

    > Howdy,
    >
    > On past .NET projects, I only had System.Web.UI.Page forms. One
    > application needed a set of functions to do processing against the
    > Page, Session and Request objects associated with the current Form. I
    > handled this by making a new class (BasePage) which inherits from
    > System.Web.UI.Page. Each form would then inherit from BasePage rather
    > than System.Web.UI.Page.
    >
    > I am now on a project that has both System.Web.UI.Page and
    > System.Web.UI.UserControl forms. I want to do the same type of
    > BasePage processing for the UserControl screens, but I can't inherit
    > them from BasePage. Currently, I made two classes that are identical,
    > except that each inherit from the respective System.Web.UI object.
    > Obviously, I would like a single class that would handle both types of
    > forms, but I can't figure out the proper way to do it. I could use a
    > clue.
    >
    > Thanks
    > Dan
    >
    >
    =?Utf-8?B?RWx0b24gVw==?=, Jan 24, 2006
    #2
    1. Advertising

  3. DanG

    Bruce Barker Guest

    this would be multi-inheritance, which c# (and the clr) do not support. the
    best you can do is create a common interface that both expose. the internal
    routines should call common code.

    -- bruce (sqlwork.com)


    "DanG" <> wrote in message
    news:...
    > Howdy,
    >
    > On past .NET projects, I only had System.Web.UI.Page forms. One
    > application needed a set of functions to do processing against the
    > Page, Session and Request objects associated with the current Form. I
    > handled this by making a new class (BasePage) which inherits from
    > System.Web.UI.Page. Each form would then inherit from BasePage rather
    > than System.Web.UI.Page.
    >
    > I am now on a project that has both System.Web.UI.Page and
    > System.Web.UI.UserControl forms. I want to do the same type of
    > BasePage processing for the UserControl screens, but I can't inherit
    > them from BasePage. Currently, I made two classes that are identical,
    > except that each inherit from the respective System.Web.UI object.
    > Obviously, I would like a single class that would handle both types of
    > forms, but I can't figure out the proper way to do it. I could use a
    > clue.
    >
    > Thanks
    > Dan
    >
    Bruce Barker, Jan 24, 2006
    #3
  4. DanG

    DanG Guest

    I was thinking ... (uh-oh)

    The UserControls are on a form which inherits from System.Web.UI.Page.
    Can I change that form to use BasePage, and then reference its
    functions from the UserControl forms?

    Using some of Elton's code, I tried adding
    Dim parentPage As BasePage = CType(Me.Page, BasePage)
    and then attempted to reference parentPage.<BasePage function>, but it
    didn't work.
    DanG, Jan 24, 2006
    #4
  5. DanG

    DanG Guest

    Doh!

    I had the old BasePage functions still set to Protected. Had to make
    them Public.

    Thanks, guys
    Dan
    DanG, Jan 25, 2006
    #5
    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. Joel Barsotti
    Replies:
    4
    Views:
    2,161
    Joel Barsotti
    Oct 30, 2003
  2. SpaceMarine

    problem while inheriting a UserControl base

    SpaceMarine, Oct 4, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    373
    SpaceMarine
    Oct 4, 2008
  3. Chris Glenn

    Controls inheriting ListControl will not fire in UserControl

    Chris Glenn, Mar 6, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    115
  4. Kan Grewal

    Web Usercontrol in a Web Usercontrol not displaying...

    Kan Grewal, Jul 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    112
    Kan Grewal
    Jul 7, 2004
  5. SpaceMarine

    problem while inheriting a UserControl base

    SpaceMarine, Oct 3, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    138
    SpaceMarine
    Oct 3, 2008
Loading...

Share This Page