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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Web.UI.Page class within another class 1

Status
Not open for further replies.

Billkamm

Programmer
Feb 9, 2006
74
US
I have several webpages that use the same code in the codebehind to genereate parts of the web page. I would like to put this code into another class or module and share it among all of the pages in my class.

The problem is that hese procedures use methods such Response.Write and Application() and some of them need to be passed various controls from the page.

Is there a way that I can separate out this code from the code behind? I've tried Imports System.Web.UI.Page, but that apparently didn't work at all lol.
 
So are you wanting to do something like asp.net 2.0 masterpages?
 
I'm using ASP.Net 1.0. I don't know what a master page, but it sounds like something I could use for this lol.

It was recommended to me that I either do something like
HttpContext.Current.Response.Write("Some String")

Or my utility class inheirt Web.UI.Page and then have all my web pages inherit the utility class.
 
First of all you shouldn't be using Response.Write to write any parts of your page out.

Secondly, you are looking for something called "Page Inheritance".


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm: I realize that now, but at the moment my website I have been working on for 2 months now is a giant mixture of classic ASP and ASP.Net and it is a large nightmare, but I can't exactly dump 2 months of code because of deadlines, so I'm finding work arounds to fix the damage.
 
There are two options that come to mind immediately.

The first is to create your own base page that inherits from Page, then have your Pages inherit from that base.

The second method would be to create a class that accepts an instance of System.Web.UI.Page as an argument, then performs manipulations accordingly (via Page.Response.Write or whatever).

The first method makes it easy to respond to points in the Page lifecyle and requires less code, but the second method would be more cohesive and flexible.
 
OK, so try to use methods that will limit the damage of your existing code. For example, what both BoulderBum and I have suggested, is page inheritance. e.g.


Extending on this, there are also methods that will inherit a particular template as well as the Page class e.g.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top