473,499 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Web.UI.Page Inheritance

dan
I have created a class called BasePage that inherits from
System.Web.UI.Page so that I can implement a "template"
for all pages in an app. My BasePage class is in a class
library project and there is also a web app in the same
solution that has a project reference back to the class
library.

When I create a new web form in VS.NET, I simply change
the code behind class to inherit from BasePage instead of
System.Web.UI.Page.

Everything works great until I try to open a web form in
design mode... Then I get the following error.
************************************************** ******
The file could not be loaded into the Web Forms designer.
Please correct the following error and then try loading it
again.

An exception occured while trying to create and instance
of DDN.ClassLib.BaseClasses.BasePage. The exception
was "Object reference not set to an instance of an
object.".

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

What is this all about? Everything works great when I
compile the classlibrary (with the BasePage class) and the
project. What is Visual Studio looking for?

Any help is greatly appreciated!

Here is the (simplified) code from my BasePage.cs:
************************************************** *******
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace DDN.ClassLib.BaseClasses
{
public class BasePage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
lblPgTitle;
public PageUtilities pgUtil = new
PageUtilities();

public string PgTitle
{
get
{
return ViewState
["PgTitle"] == null ? string.Empty : (string) ViewState
["MsgPgTitle"];
}
set
{
ViewState["PgTitle"] =
value;
lblPgTitle.Text = value;
}
}

protected override void OnInit
(System.EventArgs e)
{
BuildPage( GenerateHtmlForm() );
this.DataBind();
ddRelTasks.Attributes.Add
("onChange", "RelTask();");
base.OnInit(e);
}

private HtmlForm GenerateHtmlForm()
{
HtmlForm form = new HtmlForm();
form.ID = "Form1";
AddControlsFromDerivedPage(form);
return form;
}

private void AddControlsFromDerivedPage
(HtmlForm form)
{
int count = this.Controls.Count;
for( int i = 0; i<count; ++i )
{
System.Web.UI.Control
ctrl = this.Controls[0];
form.Controls.Add( ctrl );
this.Controls.Remove(
ctrl );
}
}
private void BuildPage( HtmlForm form )
{

this.Controls.AddAt( 0, new
LiteralControl( @"
<html>
<head>
<title>MyPage</title>
<link
rel='stylesheet' href='/def/inc_style.css' type='text/css'>
</head>
<body>"));

this.Controls.Add( form );

form.Controls.AddAt(1, new
LiteralControl( @"
<TABLE WIDTH='1000'
BORDER='1' CELLPADDING='0' CELLSPACING='0' BGCOLOR='white'
ID='Table1'>
<TBODY>
<TR>

<TD VALIGN='top'>

<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0'
CELLSPACING='0' ID='Table2' BGCOLOR='white'>

<TBODY>

<TR class=darkbackcell>

<TD VALIGN='top'>"));

lblPgTitle = new Label();
form.Controls.AddAt(8,
lblPgTitle );
form.Controls.AddAt
(form.Controls.Count, new LiteralControl( @"
</td>

</tr>

</TABLE>

</TD>

</TR>

</TABLE>

<br>

</TD>

</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<TABLE ID='Table9'><TR><TD
HEIGHT='25' COLSPAN='2' VALIGN='top'></TD></TR></TABLE>
"));

this.Controls.Add(new
LiteralControl(@"</body></html>"));
}
}
}


Nov 18 '05 #1
2 2535
dan wrote:
I have created a class called BasePage that inherits from
System.Web.UI.Page so that I can implement a "template"
for all pages in an app. My BasePage class is in a class
library project and there is also a web app in the same
solution that has a project reference back to the class
library.

When I create a new web form in VS.NET, I simply change
the code behind class to inherit from BasePage instead of
System.Web.UI.Page.

Everything works great until I try to open a web form in
design mode... Then I get the following error.
************************************************** ******
The file could not be loaded into the Web Forms designer.
Please correct the following error and then try loading it
again.

An exception occured while trying to create and instance
of DDN.ClassLib.BaseClasses.BasePage. The exception
was "Object reference not set to an instance of an
object.".

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

What is this all about? Everything works great when I
compile the classlibrary (with the BasePage class) and the
project. What is Visual Studio looking for?

Any help is greatly appreciated!

Here is the (simplified) code from my BasePage.cs:
************************************************** *******
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace DDN.ClassLib.BaseClasses
{
public class BasePage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
lblPgTitle;
public PageUtilities pgUtil = new
PageUtilities();

public string PgTitle
{
get
{
return ViewState
["PgTitle"] == null ? string.Empty : (string) ViewState
["MsgPgTitle"];
}
set
{
ViewState["PgTitle"] =
value;
lblPgTitle.Text = value;
}
}

protected override void OnInit
(System.EventArgs e)
{
BuildPage( GenerateHtmlForm() );
this.DataBind();
ddRelTasks.Attributes.Add
("onChange", "RelTask();");
base.OnInit(e);
}

private HtmlForm GenerateHtmlForm()
{
HtmlForm form = new HtmlForm();
form.ID = "Form1";
AddControlsFromDerivedPage(form);
return form;
}

private void AddControlsFromDerivedPage
(HtmlForm form)
{
int count = this.Controls.Count;
for( int i = 0; i<count; ++i )
{
System.Web.UI.Control
ctrl = this.Controls[0];
form.Controls.Add( ctrl );
this.Controls.Remove(
ctrl );
}
}
private void BuildPage( HtmlForm form )
{

this.Controls.AddAt( 0, new
LiteralControl( @"
<html>
<head>
<title>MyPage</title>
<link
rel='stylesheet' href='/def/inc_style.css' type='text/css'>
</head>
<body>"));

this.Controls.Add( form );

form.Controls.AddAt(1, new
LiteralControl( @"
<TABLE WIDTH='1000'
BORDER='1' CELLPADDING='0' CELLSPACING='0' BGCOLOR='white'
ID='Table1'>
<TBODY>
<TR>

<TD VALIGN='top'>

<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0'
CELLSPACING='0' ID='Table2' BGCOLOR='white'>

<TBODY>

<TR class=darkbackcell>

<TD VALIGN='top'>"));

lblPgTitle = new Label();
form.Controls.AddAt(8,
lblPgTitle );
form.Controls.AddAt
(form.Controls.Count, new LiteralControl( @"
</td>

</tr>

</TABLE>

</TD>

</TR>

</TABLE>

<br>

</TD>

</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<TABLE ID='Table9'><TR><TD
HEIGHT='25' COLSPAN='2' VALIGN='top'></TD></TR></TABLE>
"));

this.Controls.Add(new
LiteralControl(@"</body></html>"));
}
}
}


It's trying to run your init event, etc. to let you see it in the
designer. I'd check to see if the current HttpContext is null before
doing your BuildPage, etc. It should be able to display then hopefully
(not your template, just the derived page HTML)....

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #2
MNF
Craig Deelsnyder <cdeelsny@SPAM_BE_GONEyahoo.com> wrote in message news:<Om**************@TK2MSFTNGP09.phx.gbl>...
It's trying to run your init event, etc. to let you see it in the
designer. I'd check to see if the current HttpContext is null before
doing your BuildPage, etc. It should be able to display then hopefully
(not your template, just the derived page HTML)....


Winforms.Form has DesignMode property that you can check in your base
class methods to identify is it in Run mode or Design mode. I am not
aware, is something similar exists in WebForms.Page.
Does anyone know?

Michael Freidgeim.
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2578
by: Greg G | last post by:
I just added a "Testimonial Letters" page for our band's web site. On a whim, I decided to try using a drop cap to start each paragraph. I looked up how to do it on someone's web site. His...
0
1359
by: Dan | last post by:
I posted a similar post regarding problems with VS.NET design mode. I fixed that problem (with much thanks to this newsgroup) but now I have a second problem. I have created a class called...
0
1054
by: Alistair McRonald | last post by:
I have been experimenting with an ASP.Net templating system based around inheriting from the System.Web.UI.Page class. I am however having some issues with loading the viewstate. During the...
5
2034
by: Invalidlastname | last post by:
Hi, I just read the pattern "Design and Implementation Guidelines for Web Clients" from MSDN. Here is my question. In chapter 3,...
1
2568
by: Chuck Haeberle | last post by:
We have need to share functionality across all of our application web pages, so we decided to subclass from System.Web.UI.Page. When we create a new aspx, the Visual Studio designer automatically...
7
1686
by: tshad | last post by:
I have a control that I am using from Metabuilders that requires you to use: <%@ Page Inherits="MetaBuilders.WebControls.DialogPage" %> How do I inherit my code-behind page or another object...
4
6720
by: DanG | last post by:
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...
2
2483
by: Peter Michaux | last post by:
Douglas Crockford doesn't seem to like JavaScript's built-in syntax for building new objects based on a prototype object. The constructor function, its prototype property and the "new" keyword all...
3
1369
by: Hillbilly | last post by:
I just deployed using FTP to send .aspx and .cs files alike and discovered the base class I use with Master Pages is apparently causing problems --unidentified at the moment-- but a test page that...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.