Intercept html before rendering

A

Adam Smith

Not sure if this is the best place for this but here goes...

I'm trying to create a dynamic newsletter generator.
There will be several controls to select from to generate the layout of the
newsletter etc...
Then a preview of the newsletter as generated by a variety of controls, I've
stuck all these in a Panel control just for the sake of being tidy.

THEN comes a simple text box. However, what I want in here is the html
output from the Panel control, i.e. everything that is contained between
those <div> tags that Panel creates.

Theres got to be a simple way of doing this, but I can't make head nor tale
of some of the prerender or rendercontents methods.

P.S. I wont be offended if you treat me like a total novice :D

Thanks in advance,
Adam
 
A

Alex Papadimoulis

Adam,

I can't think of a specific way to do this off hand, but I'm guessing that
you'll need to override the Render method on your page class, and handle
your textbox in there (possibly by manipulating the HTML stream). You could
also try overriding the REdners method on your Textbox, which would require
that you create a custom control that inherits from it.

GoodLuck!
-- Alex Papadimoulis
 
H

Hans Kesting

Adam Smith said:
Not sure if this is the best place for this but here goes...

I'm trying to create a dynamic newsletter generator.
There will be several controls to select from to generate the layout of the
newsletter etc...
Then a preview of the newsletter as generated by a variety of controls, I've
stuck all these in a Panel control just for the sake of being tidy.

THEN comes a simple text box. However, what I want in here is the html
output from the Panel control, i.e. everything that is contained between
those <div> tags that Panel creates.

Theres got to be a simple way of doing this, but I can't make head nor tale
of some of the prerender or rendercontents methods.

P.S. I wont be offended if you treat me like a total novice :D

Thanks in advance,
Adam

If I understand correctly, you have an aspx page (possibly containing ascx's)
and ultimately some Panels. The html-output of this page is the formatted
newsletter you want to send by mail, from within some other page or component.

It is possible to request a page from within your own code to that page
(see System.Net.HttpWebRequest). This way you can get the html generated by
that page, which you can then send by email.

Hans Kesting
 
A

Adam Smith

Thanks for your responses guys, let me explain a little further:

Page layout:

Web Controls (a couple of checkbox lists currently)

Preview of newsletter (contained in a panel at present)

Textarea (should contain the html of the panel above (and only the panel))


So as you can see... what I really want to do is dynamically create a
newsletter of pure html. Later store this in a db and send them out in
e-mails.
So what I'd like to do, is grab the Panel control before it renders and copy
the text to the textarea control. I'm not married to having it in a Panel,
that was just my initial idea of trying to grab the panel controls output.

p.s. Alex, I'm thinking along the same lines. Something to do with
capturing render data, unfortunately I can't find any practical
demo's of this.
Hans, nice tip, I may have to use that elsewhere :D

----- Original Message -----
From: "Adam Smith" <none>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, May 26, 2004 12:27 PM
Subject: Intercept html before rendering
 
A

Alex Papadimoulis

Adam,

Another solution would of course be to use Client-Side javascript to do it.

<script>
document.getElementById('<%=myTextBox.ClientID%>').value =
document.getElementById('<%=MyPanel.ClientID%>').innerHtml;
</script>

-- Alex Papadimoulis
 
S

Scott Allen

Hi Adam:

I have not tried this with a panel, but I think it should work...

I've used RenderControl with a DataGrid to save the HTML the grid
generates and sent the HTML off in an email. In the easiest case it is
just setting up the correct StringWriter and HtmlTextWriter objects to
save the results.

There is some example code here:

http://odetocode.com/Code/86.aspx

I'd be very interested to hear if this works for your scenario.

HTH,
 
A

Adam Smith

Like a charm, thanks scott.

And thanks to everyone else who responded, all good suggestions.
 

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

Top