Abstract Base Page / UserControl

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Abstract Base Page / UserControl

    Our current solution has a number of ASP.NET pages with very similar functionality. We would like to move the common functions into a base class that inherits from System.Web.UI.Page, and then force the child classes to override certain functions of that class.

    The best way to do this is to define the base class as "MustInherit" and put "MustOverride" on the functions that must be overridden.

    However, when we do this, whenever we attempt to open the aspx that inherits from the base class, we recieve the error:

    "The file could not be opened in the Web Form designer. Please correct the following error and try again:

    Type Abstract

    Make sure all the classes used in the page are built or referenced in the project. Click Help for more information."

    We have noticed similar behaviour when attempting to inherit a UserControl from an abstract class.

    Two questions:

    1) Is there any way of having a code-behind class inherit from an abstract (mustinherit) class without seeing the above behaviour in the designer?

    2) Will the above behaviour impact the solution at all? We are still able to compile, the only effect we have noticed is that we cannot open the web form in the .NET designer.

    Example Code:

    PARENT CLASS:
    Public MustInherit Class ParentClass
    Inherits System.Web.UI.Page

    Protected MustOverride Function GetMessageFromChild()

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Response.Write(Me.GetMessageFromChild)
    End Sub
    End Class


    CHILD CLASS:
    Public Class ChildClass
    Inherits ParentClass

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Protected Overrides Function GetMessageFromChild() As Object
    Return "Here is a message from a child page"
    End Function
    End Class

    Web Form:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="ChildClass.aspx.vb" Inherits="WebApplication1.ChildClass"%>
    <html>
    <body>
    <form id="Form1" method="post" runat="server">
    </form>
    </body>
    </html>

    Murray Gill Guest

  2. Similar Questions and Discussions

    1. When base class is used for UserControl, VS designer fails to load ASCX file
      The problem is that I cannot use VS graphical designer to design my ASCX controls that do not inherit directly from System.Web.UI.UserControl but...
    2. Getting data from a usercontrol before containing page ends its page load
      How do I load a user control in a web form first, so that the web form's page_load acts according to events on the user control? In my code...
    3. MustInherit base class inherited by UserControl
      Following on from this discussion http://www.dotnet247.com/247reference/msgs/29/146830.aspx i'm having the same problem, the classes that i...
    4. Base usercontrol class and wrapping
      I have created a base class that inherits UserControl. The purpose of this class is to implement common functionality for all of my usercontrols...
    5. Page Base Classes
      ..NET seems to support inheritance of the Page class, but it doesn't seem to render the information from the base class properly, at least not by...
  3. #2

    Default Re: Abstract Base Page / UserControl

    Hi,

    1) Is there any way of having a code-behind class inherit from an
    abstract (mustinherit) class without seeing the above behaviour in the
    designer? - NO

    you can look at Felix Wu [MS] replay :
    [url]http://www.developersdex.com/asp/message.asp?p=1116&ID=%3CezFVyhlwCHA%2E[/url]
    2532%40TK2MSFTNGP10%3E


    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139