473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ASP.NET 2.0: custom base Page class (derived from System.Web.UI.Page)

I had developed a custom base page class for the 1.1 framework which I
have now migrated to the 2.0 framework. I discovered that the new
partial class system -- which appears to "automagically" assign the
Page_Load method as the Load event handler in the hidden partial class
-- does not carry over to derived Page classes. This being the case,
and not wanting to copy what used to be the VS generated code into
every derived page, I decided to attempt to assign the Load event
handler in the custom base class.

This is what I came up with:
/// Custom base class ////////////////////////////////////////

protected class BasePage : System.Web.UI.Page
{

// ctor, other code implied

override protected void OnInit(EventArgs e)
{
this.Load += new System.EventHandler(this.Page_Load);
base.OnInit(e);
}

virtual protected void Page_Load
{
// no code defined
}

} // end class
/// Derived class /////////////////////////////////////////

public class MyPage : BasePage
{

// ctor, other code implied

override protected Page_Load(object sender, EventArgs e)
{
// some code
base.PageLoad(sender,e);
}

} // end class

//////////////////////////////////////////////////////////////

This seems to work like a charm. If anyone has any comments on why
this is a less-than-preferable technique, suggestions for improvement,
or a more elegant solution I would be glad to hear them!

Tom
Mnemoweb Incorporated

Dec 15 '05 #1
0 1473

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

Similar topics

0
by: Bennett Haselton | last post by:
I've noticed that if you enter the following code in the codebehind page for an .aspx page, it won't compile because the call to Trace.Write() is not valid except in methods of a class derived from...
3
by: Vincent V | last post by:
Hey im Overiding OnInit in my Custom Page class What i want to be able to do is pass in Some Values Ie PageID PageCategory, PageSubCategory How can i pass in some Vairables So my Custom Page class...
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
2
by: Mike Taylor | last post by:
I'm trying to create a base page class for my project (am new to ASP.NET, so am a bit stumped) - I'm using VS.NET 2003, btw. OK, my dummy base page class is shown below: using System; using...
4
by: David Young | last post by:
I normally work on WinForms projects, but have been recently thrust into this arena and had a questions concering access to objects stored in session. We've apparently got an object (custom...
3
by: Jordan | last post by:
Suppose I have a system that keeps track of 5 different types of "People". My intent is to have a base Person class, then 5 derived classes for each of the specific person types (e.g., Patient,...
15
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
3
by: Managed Code | last post by:
I have a BasePage class that derives from System.Web.UI.Page. All of my content pages derive from this. The derived page classes use the following MasterType declaration that follows to reference...
2
by: tshad | last post by:
I have a Base Page Class that I built am just starting to use. In my aspx page I have: <%@ Page Language="VB" trace="true" ContentType="text/html" ResponseEncoding="iso-8859-1"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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
tracyyun
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...
0
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...

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.