Inheriting an User Control in Whibey , i.e., ASP.Net 2.0

Discussion in 'ASP .Net' started by Arvind, Jan 4, 2005.

  1. Arvind

    Arvind Guest

    I am trying to inherit an User Control from one another User Control
    in ASP.Net 2.0.

    Since we have partial classes in ASP.Net 2.0, this restricts me when I
    try to do the same. I am using the code chunk below to inherit.

    public partial class DerivedUserControl_ascx : BaseUserControl_ascx

    Where BaseUserControl_ascx is the base User Control and
    DerivedUserControl_ascx is the derived User Control.

    Let me know if there is any work around / or if I am not doing it
    right.

    --
    Thanks
    Arvind
     
    Arvind, Jan 4, 2005
    #1
    1. Advertising

  2. "Arvind" <> wrote in message
    news:...
    >I am trying to inherit an User Control from one another User Control
    > in ASP.Net 2.0.
    >
    > Since we have partial classes in ASP.Net 2.0, this restricts me when I
    > try to do the same. I am using the code chunk below to inherit.
    >
    > public partial class DerivedUserControl_ascx : BaseUserControl_ascx
    >
    > Where BaseUserControl_ascx is the base User Control and
    > DerivedUserControl_ascx is the derived User Control.
    >
    > Let me know if there is any work around / or if I am not doing it
    > right.


    You haven't said what problem you're seeing.

    I tried this and saw an error saying that each partial class must derive
    from the same base class. I solved this by adding
    Inherits="BaseUserControl_ascx" to the <%@ Control %> directive.

    John Saunders
     
    John Saunders, Jan 4, 2005
    #2
    1. Advertising

  3. John

    Thanks a Ton for the reply.
    I am still getting an error even when I do the suggested steps by you.

    --
    Thanks,
    Arvind


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Arvind Khasibhatla, Jan 5, 2005
    #3
  4. Arvind

    Nate

    Joined:
    Jul 24, 2006
    Messages:
    1
    I tried this:

    derived .ascx file
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestUserControlInheritance.ascx.cs" Inherits="TestUserControlInheritanceBase" %>

    derived .ascx.cs file
    public partial class TestUserControlInheritance : TestUserControlInheritanceBase
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    }

    base .ascx file
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestUserControlInheritanceBase.ascx.cs" Inherits="TestUserControlInheritanceBase" %>

    base .ascx.cs file
    public partial class TestUserControlInheritanceBase : System.Web.UI.UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    }

    I encountered the error:
    Error 3: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

    (The use of the suffix "_ascx" makes me think something is going on I don't know about. I know that when the .ascx file compiles into a .cx file, these suffixes are added to names, but I've never seen those in the .ascx.cs file or anything the C# developer would actually type.)

    Any help will be much appreciated!
     
    Nate, Jul 24, 2006
    #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. Danny Ni
    Replies:
    1
    Views:
    324
    David Jessee
    Jan 16, 2005
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    658
    Mad Scientist Jr
    Mar 22, 2006
  3. AleXmanFree
    Replies:
    3
    Views:
    585
    Hillbilly
    Oct 9, 2008
  4. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    566
    Jonathan Wood
    Feb 2, 2010
  5. Vikas Manghani

    Inheriting from User Control

    Vikas Manghani, Oct 14, 2007, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    783
    Nathan Sokalski
    Jan 8, 2008
Loading...

Share This Page