Professional Web Applications Themes

Abstract Base Page / UserControl - ASP.NET General

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 ...

  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. #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

Similar Threads

  1. When base class is used for UserControl, VS designer fails to load ASCX file
    By Jiri Zidek in forum ASP.NET Building Controls
    Replies: 5
    Last Post: April 6th, 11:48 PM
  2. Replies: 0
    Last Post: September 7th, 04:12 AM
  3. MustInherit base class inherited by UserControl
    By Craig Edmunds via .NET 247 in forum ASP.NET Building Controls
    Replies: 2
    Last Post: July 4th, 05:00 AM
  4. Base usercontrol class and wrapping
    By AWHK in forum ASP.NET Building Controls
    Replies: 2
    Last Post: September 4th, 02:26 PM
  5. Page Base Classes
    By Tom J. in forum ASP.NET General
    Replies: 2
    Last Post: July 8th, 08:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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