ASP .Net PageBase Inherit

B

Ben Mann

Hi there,

I am starting on an ASP .Net project. I have some examples of using a base
class for pages to inherit from to allow additional properties to be used by
default. This seems like a good idea to me.

I have a namespace Company.Web. I have created a PageBase.vb file with a
PageBase class containing the the properties required. This class also
inherits the System.Web.UI.Page class.

Ive compiled my project then tried to create a new aspx page. The page is
within the same namespace and i have changed the Inherits System.Web.UI.Page
to being Inherits Company.Web.PageBase

But Visual Studio will not allow me to open the page in the Designer View.

The error is

---

The file could not be loaded into the Web Forms designer. please correct the
following error and then try loading it again:

The designer could not be shown for this file because none of the classes
within it can be displayed. The designer inspected the following classes in
the file:

Index --- The base class 'Company.Web.PageBase' could not be loaded. Ensure
the assembly has been referenced or built if it is part of the project.

Make sure all of the classes used in the page are built or referenced in the
project.

---

I have looked at the help and checked the CodeBehind and Inherits setting in
the aspx page itself and it looks fine to me.

If anyone can help, that would be great.

Many Thanks.

Ben Mann.
 
J

John Soulis [MSFT]

Hello Ben,
I have seen this happen with addins.
To determine what is causing the failure, open two instances of
VS.NET, one for the project, and one to use the debugger from to attach to
the
deven process.

Set the debugger to break on all CLR exceptions. Then try to open the
page.
Before you see the error above, you should see the exception that is
causing the error.

Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
 
B

Ben Mann

Thanks very much for your reply to my post. I'm still getting my feet wet as
far as ASP .Net is concerned and small problems like this seem to get me
stumped for ages!

I hope you don't mind me sending you an email asking for a tiny bit more
help though, if so, just tell me to go away.
:)


I've attached the debugger to my VS.Net and opened the offending page, It
generates, in total, 3 exceptions when it tries to open the page. The first
two are:

A first chance exception of type 'System.Security.SecurityException'
occurred in mscorlib.dll

Additional information: Request for the permission of type
System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

and the third is the cruncher....


A first chance exception of type
'System.Runtime.Serialization.SerializationException' occurred in
microsoft.visualstudio.dll

Additional information: The designer could not be shown for this file
because none of the classes within it can be designed. The designer
inspected the following classes in the file:

Index --- The base class 'Company.Web.pageBase' could not be loaded.
Ensure the assembly has been referenced or built if it is part of the
project.



I've read up on these exceptions, but im unsure what to do about them as
they occur in VS.Net itself.

If you've got any suggestions, that'd be really helpful.

Many Thanks.

Ben Mann.
 
J

John Soulis [MSFT]

Are you making a reference to any properties in the base class
Company.Web.pageBase?
Here is what sounds like is going on. When you try to look at the form in
the designer, the base class runs so it can be loaded in the designer.
There is a reference to something in the base class that is causing an
error that is not being handled by the designer. I would start to comment
out parts of the code in the base class to find the culprit. If the code is
not something you want to keep private, I would take a look at it too.

Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
 
B

Ben Mann

Hi John,

Thanks for getting back to me again,
I've commented out almost the entire pageBase file, but still non luck.

Most of it is lifted from the Duwamish 7 example web app. I just want to
have a parent class with an UrlBase property, (not much to ask!).

But my VS .Net has the same trouble if i try to load up any of the Duwamish
example pages that extend the PageBase class.


I've put my code for the pageBase and example aspx page below. If you could
take a look that'd be great.

pageBase.vb:


Option Explicit On
Option Strict On

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Data

Namespace Company.Web

'----------------------------------------------------------------
' Namespace: Company.Web
' Class: pageBase
'
' Description:
' The code-behind base class for all pages.
'----------------------------------------------------------------

Public Class pageBase

Inherits System.Web.UI.Page

' Private Shared ReadOnly Property UrlSuffix() As String
' Get
' UrlSuffix = HttpContext.Current.Request.Url.Host +
HttpContext.Current.Request.ApplicationPath
' End Get
' End Property


' Public Shared ReadOnly Property UrlBase() As String
' Get
' UrlBase = "http://" & UrlSuffix
' End Get
' End Property

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load


End Sub

End Class

End Namespace



and the webform1.aspx:


Option Explicit On
Option Strict On

Imports Company.Common

Namespace Company.Web

Public Class WebForm1

Inherits pageBase
'Inherits System.Web.UI.Page

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

End Class

End Namespace



Many thanks,

Ben Mann
 
J

John Soulis [MSFT]

Looks like we are narrowing this down.
Please try this, so I can determine if it is project specific or an issue
with VS.NET.
1 Start a new project.
2 Add a class file and name it cpagebase.vb
3 Add this code to the file.
Public Class cpagebase : Inherits System.Web.UI.Page
End Class

4 inherit the page in webform1.aspx
Public Class WebForm1
Inherits cpagebase
5 Add this code to the page load
Response.Write("test")

6 Build and browse.

What results do you get from this?

Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
 
B

Ben Mann

Hi John,

Thanks for that.
I tried the example below and it worked fine.

Im not sure what is wrong now.
If you've got any more suggestions, tha'd great.

Thanks yet again.

Ben Mann.
 
J

John Soulis [MSFT]

When you try to build the original project, does it build without errors?

Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
B

Ben Mann

Hi John,

Yes the project builds fine, and i can use the page that inherits the
pageBase fine as well.

Ben Mann.
 
B

Ben Mann

Hi john,

I've also just uncommented the properties that i wanted to be inherited and
they work fine as well when the project is built and the page is view in IE.

It seems to just be a VS Designer View problem....
 
J

John Soulis [MSFT]

What is the imports Company.Common?
Also, remove the namespace in the webform1.aspx and make the inherits read
Company.Web.pageBase

Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
B

Ben Mann

Hi John,

Thanks again for your help.

The Company.Common is a separate project/dll where i have put some common
database access code thats to be shared between the web app and a windows
app that access the same database.

To count this out, i've created another test page consisting of only:


Public Class test
Inherits Company.Web.pageBase

#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

End Class



I think this code is including the bit thats usually folded away, generated
by default.

Thanks

Ben Mann
 
J

John Soulis [MSFT]

Hi Ben,
It is a VS Designer issue, but only with that page or possibly the project.
We can get a new project and page to work ok. Have you been able to run my
test? Try running it without the Company.Common or any other objects. Check
in the html to make sure there are no other objects(controls ect) on the
page. Also, try adding the test page you created from my notes to this
project and see if it will work. If it does, try adding the Company.Common
to it.

Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
B

Ben Mann

Hi John,

I've just tried opening up the test project that i put together yesterday
using the test code you sent.
Though it builds and displays in IE fine, but the VS designer won't open it.

The pages still only consist of:

cpagebase.cv:

Public Class cpagebase : Inherits System.Web.UI.Page

End Class


and WebForm1.aspx:



Public Class WebForm1

Inherits cpagebase

#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

Response.Write("test")

End Sub

End Class

There's not much there for it to get wrong really.
If there's anything else that you can suggest, that'd be great.

Thanks again.

Ben Mann.
 
J

John Soulis [MSFT]

At this point, it definitly looks like a problem with the designer now that
we are seeing it in two different projects. I will see what else I can
find. Are you getting the same error message?
Thank you, John Soulis
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top