How do I reuse code in the Code-Behind section of an ASPX page 
Author Message
 How do I reuse code in the Code-Behind section of an ASPX page

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.



Tue, 15 Jun 2004 08:23:00 GMT  
 How do I reuse code in the Code-Behind section of an ASPX page
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


Quote:
> 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.



Tue, 15 Jun 2004 10:14:02 GMT  
 How do I reuse code in the Code-Behind section of an ASPX page
Jay,

Thank you very much.  Using inheritance works perfectly.  I knew there
had to be an easy way to accomplish this one.

Best Regards,
Jim


Quote:
> 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.



Tue, 15 Jun 2004 23:37:33 GMT  
 How do I reuse code in the Code-Behind section of an ASPX page
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



Quote:
> 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.



Wed, 16 Jun 2004 06:49:38 GMT  
 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.



Wed, 16 Jun 2004 08:34:03 GMT  
 How do I reuse code in the Code-Behind section of an ASPX page
Great point about the page properties. Thanks for the assistance!

Jeff



Quote:
> 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...
Quote:
> 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



> > 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.



Wed, 16 Jun 2004 09:32:24 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Code-behind file inheriting from another code-behind file

2. Creating references to Controls ID's/Names in code behind pages

3. Passing Form Fields to VB.NET Custom Business Object in an ASP.NET Code Behind Page

4. How can I retrieve the HTML codes behind a web page

5. How to set color coding w/o using code behind

6. International Issues - Locale Code Page Vs. VB Code Page

7. Looking for feedback on code handling COM/ASP and .NET/ASPx Request object

8. why write in .aspx code??!!

9. How to reuse code in Access ?

10. Reuse of Code OCX?

11. Reuse code problem

12. Warning- careful when reusing code

 

 
Powered by phpBB® Forum Software