Post process an ASP.NET page

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?
 
G

Guest

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

Juan T. Llibre

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

Yourself

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

Yourself

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

Juan T. Llibre

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
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top