Post process an ASP.NET page

  • Thread starter Thread starter Yourself
  • Start date Start date
Y

Yourself

Is there anyway of processing an ASP.NET page after the code behind has run,
but before it's presented as HTML?

What I'm trying to do is alter some of the markup that a content management
system produces, and I don't have access to the source code to recompile any
of the code behind stuff.

I guess I could put a user control on the bottom of every aspx page and in
the Page_Load method, access the controls on the page through
Parent.Page.FindControl("id").

That's what I've been trying to do, but is there any better and more
eloquent way?
 
That's what I've been trying to do, but is there any better and more
eloquent way?

You can try using the PreRender or the Render events to modify the HTML.

The HTTPModule or HTTPHandlers might be useful too.
 
re:
What I'm trying to do is alter some of the markup that a content management system produces, and I
don't have access to the source code to recompile any of the code behind stuff.

See : http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Page_PreRender is an ideal event for you to do that.
Page_Init might also be a good place.

See the order of page events at :
http://msdn2.microsoft.com/en-us/library(d=robot)/dct97kc3.aspx

I must say, however, that if you don't have access to the code-behind
( why is that ? ) doing what you want to do could turn out to be quite tricky.




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
Juan T. Llibre said:
re:

See : http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Page_PreRender is an ideal event for you to do that.
Page_Init might also be a good place.

Ok, Page_PreRender sounds like the ideal place, but (forgive my ignorance),
dosen't this go in the code-behind file for the appropriate page? i.e.
Default.aspx.cs. Therefore, the content management system will already have
this defined in the dll file that the code behind page compiled to.

How can I tell the page (Default.aspx) to use the Page_PreRender method from
a different source? or can't I?
See the order of page events at :
http://msdn2.microsoft.com/en-us/library(d=robot)/dct97kc3.aspx

I must say, however, that if you don't have access to the code-behind
( why is that ? ) doing what you want to do could turn out to be quite
tricky.

All I really want to do is loop through each control (HtmlGenericControl)
and convert the tag name to lowercase, because the CMS outputs tags like
LINK and H1 as it is, which isn't valid XHTML.
 
Spam Catcher said:
You can try using the PreRender or the Render events to modify the HTML.

The HTTPModule or HTTPHandlers might be useful too.

Yeah they sound like they might do the trick, but how can get to a pages
controls from a HTTPModule or HTTPHandler? I can't seem to find any
information on that...
 
re:
Ok, Page_PreRender sounds like the ideal place, but (forgive my ignorance),
dosen't this go in the code-behind file for the appropriate page?

How can I tell the page (Default.aspx) to use the Page_PreRender
method from a different source? or can't I?

Why wouldn't you be able to ?

Compile a helper assembly and do whatever you'd like in it,
calling its procedures from your inline page code :

MyPreRenderAssembly.vb:
===================

Imports System
Imports System.Web
Imports System.Web.UI

Namespace myControls

Public Class ControlEvents
Inherits Control

Protected Overrides Sub OnPreRender( e As EventArgs )
Context.Response.Write( "<li> OnPreRender Event!" )
End Sub

End Class

End Namespace



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top