
How do I reuse code in the Code-Behind section of an ASPX page
Jeff,
Web Form Visual Inheritance is not really there... I would expect to be able
to handle some events or override methods would allow to me to inject code
into the page, Control.Render for example.
There was an article on DevX on one method of doing, but I cannot find it
right now... Possible its
http://www.devx.com/upload/free/features/vbpj/2001/12dec01/an0112/an0...
sp, which is for members only now...
Using modules, you would not have access the properties of the Page, you
would need to pass them as parameters (Response, Request, Session,
Application, Server, Cache...). And of course it would not be OOP ;-). Not
to say it would not be useful in some applications...
Hope this helps
Jay
Quote:
> Jay,
> This was a very useful response as I was unaware that you could inherit
from
> another page in Web Forms, I guess because there is not a menu item like
> there is in Windows Forms. I just tried it and the code is available (and
> the parent page's page_load code is called), but there is no visual
> inheritance. Is there any way to share visual elements?
> Also, any problems in using modules to share code in this scenario instead
> (besides not being OOP)?
> Thanks!
> Jeff Rhodes
message
> > Jim,
> > Use inheritance. This assumes you are using VS.NET CodeBehind model, not
> the
> > src= code behind model.
> > Your page1.aspx would inherit from Class Page1 in page1.aspx.vb
> > Class Page1 would inherit from class PageBase. (manual change source)
> > Class PageBase would be a 'standalone' class that is added to the
project.
> > Which inherits from System.Web.UI.Page
> > Your 'block of code' would be implemented as a method of PageBase. Page1
> > would invoke the method where the block is needed...
> > Depending on where the block is really needed, PageBase could override
one
> > of Page's methods, or handle one of the Events of Page. Leaving Page1
> > unaware...
> > Hope this helps
> > Jay
> > > Does anyone know how to "include" a block of code in the code-behind
> > > (.vb) file of an ASPX page that retains the ability to call a
> > > Response.Redirect?
> > > I DO NOT want to use an include file on the Design/HTML side. What I
> > > want, is to have a block of code that I can reuse in the Code-Behind
> > > section of my ASPX pages. In this block of code I am doing a
> > > Response.Redirect (this response.redirect cannot be stripped out of
> > > the code block). I have been unsuccessful in implementing a
> > > Response.Redirect from a Class file directly.
> > > Does anyone know how to include a file in the Code-Behind section of
> > > an ASPX Page or Perform a Response.Redirect from a Class File?
> > > Any help on this matter is greatly appreciated.