Intercepting what ASP.NET renders: how fine-grained?

G

Guest

ASP.NET is a kind of "engine" that takes declarative markup and code and
renders these instructions into presentational forms. And every page is a
class.

With that in mind I'm wondering,

a) how to intercept the rendered output and do further programmatic things
with it;
and
b) how coarse or finely grained the control might be. One could envision the
ASP.NET designers giving you programmatic access to subselections of the
page HTML (e.g. <head> ... </head> <body> ... </body> ). Maybe even a page
hieararchy.

I'm interested in rendering content into various non-HTML forms (pdf, Flash
text, multipart mails) and I'd like the ASP.NET engine to do the hard work
of preprocessing some of this content; these ideas are especially
interesting with the availability of skins, themes, and master pages in
asp.net 2.0.

Barring programmatic access, I suppose I can yank what I want using regular
expressions, but I'm curious if there's a better way.

Thanks,
-KF
 
M

martin

you can modify the HTML that is rendered to the screen in the "Render"
method of the page.

or if you want to alter the HTML of every page in your application you can
just inherit from a common base page.

you can definatly use regular expressions to change the HTML at this point.

HTH

cheers

martin.
 
R

Robbe Morris [C# MVP]

You could certainly use httphandlers to intercept the outgoing
stream and modify it. This article is a bit off topic but the
code sample does demonostrate how and where to do this:

http://www.eggheadcafe.com/articles/hijacksession.asp

You could also load the rendered output into a DOM
and work with it.

http://www.eggheadcafe.com/articles/parsinghtml.asp

There are a variety of things you could do...

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.masterado.net

Earn $$$ money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp
 
B

Bruce Barker

the rendered output is just a i/o stream of the html content. you can do
anything you want to it, but you would have to reparse it.

the preRender event is the last change to modifiy in the memory model of the
"parsed" page. only items with a runat=server are parsed into the tree,
everty thiong between server objects is parsed as a literal

image the following html:

<html>
<head>
<link id=link1 runat=server href="foo.css" \>
</head>
<body>
<span id=span1 runat=server><font size=1>hi</font></span>
</body>
</html>

is parsed into 5 controls

l1 = new LiteralControl("<html>\n<head>\n");

link1 = new HtmlGenericControl("link");
link1.ID = "link1"
link1.Attributes.Add("href","foo.css");

l2 = new LiteralControl("</head>\n<body>");

span1 = new HtmlGenericControl("span");
span1.ID = "span1";
span1.InnerHtml = "<font size=1>hi</font>";

l3 = new LiteralControl("</body>\n</head>");

these five controls will be added to the pages Controls collection.

-- bruce (sqlwork.com)
 
B

Brock Allen

In ASP.NET 2.0 this can be done with the new Adapter rendering model. It's
intended to allow external code (the "adapter") control rendering when there
is an alternate client being used (such as a handheld device).
 

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
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top