I have created a class called BasePage that inherits from
System.Web.UI.P age 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.P age.
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.Ba seClasses.BaseP age. 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.H tmlControls;
using System.Web.UI.W ebControls;
namespace DDN.ClassLib.Ba seClasses
{
public class BasePage : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l
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.EventAr gs e)
{
BuildPage( GenerateHtmlFor m() );
this.DataBind() ;
ddRelTasks.Attr ibutes.Add
("onChange", "RelTask(); ");
base.OnInit(e);
}
private HtmlForm GenerateHtmlFor m()
{
HtmlForm form = new HtmlForm();
form.ID = "Form1";
AddControlsFrom DerivedPage(for m);
return form;
}
private void AddControlsFrom DerivedPage
(HtmlForm form)
{
int count = this.Controls.C ount;
for( int i = 0; i<count; ++i )
{
System.Web.UI.C ontrol
ctrl = this.Controls[0];
form.Controls.A dd( ctrl );
this.Controls.R emove(
ctrl );
}
}
private void BuildPage( HtmlForm form )
{
this.Controls.A ddAt( 0, new
LiteralControl( @"
<html>
<head>
<title>MyPage </title>
<link
rel='stylesheet ' href='/def/inc_style.css' type='text/css'>
</head>
<body>"));
this.Controls.A dd( form );
form.Controls.A ddAt(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=darkbackc ell>
<TD VALIGN='top'>") );
lblPgTitle = new Label();
form.Controls.A ddAt(8,
lblPgTitle );
form.Controls.A ddAt
(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.A dd(new
LiteralControl( @"</body></html>"));
}
}
} 2 2542
dan wrote: I have created a class called BasePage that inherits from System.Web.UI.P age 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.P age.
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.Ba seClasses.BaseP age. 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.H tmlControls; using System.Web.UI.W ebControls;
namespace DDN.ClassLib.Ba seClasses { public class BasePage : System.Web.UI.P age { protected System.Web.UI.W ebControls.Labe l 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.EventAr gs e) { BuildPage( GenerateHtmlFor m() ); this.DataBind() ; ddRelTasks.Attr ibutes.Add ("onChange", "RelTask(); "); base.OnInit(e); }
private HtmlForm GenerateHtmlFor m() { HtmlForm form = new HtmlForm(); form.ID = "Form1"; AddControlsFrom DerivedPage(for m); return form; }
private void AddControlsFrom DerivedPage (HtmlForm form) { int count = this.Controls.C ount; for( int i = 0; i<count; ++i ) { System.Web.UI.C ontrol ctrl = this.Controls[0]; form.Controls.A dd( ctrl ); this.Controls.R emove( ctrl ); } } private void BuildPage( HtmlForm form ) {
this.Controls.A ddAt( 0, new LiteralControl( @" <html> <head> <title>MyPage </title> <link rel='stylesheet ' href='/def/inc_style.css' type='text/css'> </head> <body>"));
this.Controls.A dd( form );
form.Controls.A ddAt(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=darkbackc ell>
<TD VALIGN='top'>") );
lblPgTitle = new Label(); form.Controls.A ddAt(8, lblPgTitle ); form.Controls.A ddAt (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.A dd(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
Craig Deelsnyder <cdeelsny@SPAM_ BE_GONEyahoo.co m> wrote in message news:<Om******* *******@TK2MSFT NGP09.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 example looked
good, but had a lot of "pixel sized" elements. I'm no expert, but I
don't like when pages go haywire on different browsers, or with...
|
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 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...
|
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 "Init" sequence I load my template and then load the body content
of the page which is pasted into the template.
However, if I post back I get an...
|
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,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/diforwc-ch03.asp ,
the article mentions using page inheritance to maintain common page layout.
We currently use page inheritance...
|
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 puts in the codebehind, as such:
public class testsubclass : System.Web.UI.Page
We change this to be:
public class testsubclass :...
| |
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 that may require an
inherit also?
Thanks,
Tom
|
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 current Form. I
handled this by making a new class (BasePage) which inherits from
System.Web.UI.Page. Each form would then inherit from BasePage...
|
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 seem very
offensive to him. For over a year, Crockford has proposed an alternate
way of using prototypes like this
function object(o) {
function...
|
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 inherits from
System.Web.UI.Page and its MasterPage loads fine.
I imagine this context may have occurred for others using a base class and
wonder...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |