Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheriting from a base page class / Alternatives

Status
Not open for further replies.

dragonwell

Programmer
Oct 21, 2002
863
US
I've been creating my own "BasePage" class which inherits from System.Web.UI.Page. In all my code behind classes I inherit from my BasePage, instead of System.Web.UI.Page. This way, I can create properties in my Base page that I want all my pages to have, and I can create commonly used objects in the BasePage constructor. This is a great aid to development. Sometimes I also go as far as to override System.Web.UI.Page's render method to include my own hard-coded content as a form a templating.

The only problem is, Visual Studio.NET's designer hates my pages that do not inherit from System.Web.UI.Page. Most of the time it won't even render the page in designer, just html.

I was wondering if anyone has done similarly and found a work-around to this?

OR

is there another way to include common objects and properties in all my pages? I've been experimenting with the Global.asax file and the Application_BeginRequest event, but so far I've only been able to add objects to the context and not actually instantiate anything that could be used on a page.

Anyone?

Regards,
David
 
Well, I fixed my problem. If anyone's interested - apparently Visual Studio attempts to "run" some aspect of your code when going into Designer Mode. If an error occurs on the class that the Page inherits from, it can;t load the Designer. I was using "Page.Context" in my base class, which always returns the Request at runtime - but it is null during design time. Now, I check to see if it is null before trying to use it and everyone's happy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top