473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Retrieving Rendered Source from Page

Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text
of itself. Can this be done? I have tried looping through all my
controls and rendering them as per your example but am hitting some walls.

Any ideas?

Kind Regards

Ray Booysen
--
Ray Booysen
rj********@rjb.za.net
Mar 1 '06 #1
6 1242
Ray Booysen wrote:
Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text
of itself. Can this be done? I have tried looping through all my
controls and rendering them as per your example but am hitting some walls.

Any ideas?

Kind Regards

Ray Booysen

I also meant to say this is in an ASP.NET 1.1 project.

--
Ray Booysen
rj********@rjb.za.net
Mar 1 '06 #2
Hey Ray,

Here's something adapted from ASP.NET 2.0 Cookbook from O'Reilly
(http://www.oreilly.com/catalog/aspnetckbk2/)

This works in 2.0. Haven't tried it in 1.1 Maybe it will give you an idea?

Ken
Microsoft MVP [ASP.NET]
<%@ page language="VB" validaterequest="false" enableviewstate="false" %>

<script runat="server">

Protected Overrides Sub Render _
(ByVal writer As System.Web.UI.HtmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.html"
Dim renderedOutput As StringBuilder = Nothing
Dim strWriter As IO.StringWriter = Nothing
Dim tWriter As HtmlTextWriter = Nothing
Dim outputStream As IO.FileStream = Nothing
Dim sWriter As IO.StreamWriter = Nothing
Dim filename As String

Try
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New IO.StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)

MyBase.Render(tWriter)

'save the rendered output to a file
filename = Server.MapPath(".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(filename, _
IO.FileMode.Create)
sWriter = New IO.StreamWriter(outputStream)
sWriter.Write(renderedOutput.ToString())
sWriter.Flush()
writer.Write(renderedOutput.ToString())
Finally

'clean up
If (Not IsNothing(outputStream)) Then
outputStream.Close()
End If

If (Not IsNothing(tWriter)) Then
tWriter.Close()
End If

If (Not IsNothing(strWriter)) Then
strWriter.Close()
End If
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Capture Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem>red</asp:listitem>
<asp:listitem>blue</asp:listitem>
<asp:listitem>green</asp:listitem>
</asp:dropdownlist></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text of
itself. Can this be done? I have tried looping through all my controls
and rendering them as per your example but am hitting some walls.

Any ideas?

Kind Regards

Ray Booysen
--
Ray Booysen
rj********@rjb.za.net

Mar 1 '06 #3
Hi Kevin.

I'll give it a shot. Thanks!

Ken Cox - Microsoft MVP wrote:
Hey Ray,

Here's something adapted from ASP.NET 2.0 Cookbook from O'Reilly
(http://www.oreilly.com/catalog/aspnetckbk2/)

This works in 2.0. Haven't tried it in 1.1 Maybe it will give you an idea?

Ken
Microsoft MVP [ASP.NET]
<%@ page language="VB" validaterequest="false" enableviewstate="false" %>

<script runat="server">

Protected Overrides Sub Render _
(ByVal writer As System.Web.UI.HtmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.html"
Dim renderedOutput As StringBuilder = Nothing
Dim strWriter As IO.StringWriter = Nothing
Dim tWriter As HtmlTextWriter = Nothing
Dim outputStream As IO.FileStream = Nothing
Dim sWriter As IO.StreamWriter = Nothing
Dim filename As String

Try
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New IO.StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)

MyBase.Render(tWriter)

'save the rendered output to a file
filename = Server.MapPath(".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(filename, _
IO.FileMode.Create)
sWriter = New IO.StreamWriter(outputStream)
sWriter.Write(renderedOutput.ToString())
sWriter.Flush()
writer.Write(renderedOutput.ToString())
Finally

'clean up
If (Not IsNothing(outputStream)) Then
outputStream.Close()
End If

If (Not IsNothing(tWriter)) Then
tWriter.Close()
End If

If (Not IsNothing(strWriter)) Then
strWriter.Close()
End If
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Capture Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem>red</asp:listitem>
<asp:listitem>blue</asp:listitem>
<asp:listitem>green</asp:listitem>
</asp:dropdownlist></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text of
itself. Can this be done? I have tried looping through all my controls
and rendering them as per your example but am hitting some walls.

Any ideas?

Kind Regards

Ray Booysen
--
Ray Booysen
rj********@rjb.za.net


--
Ray Booysen
rj********@rjb.za.net
Mar 1 '06 #4
It's Ken, not Kevin, but let us know how it works for you?

Ken

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
Hi Kevin.

I'll give it a shot. Thanks!

Ken Cox - Microsoft MVP wrote:
Hey Ray,

Here's something adapted from ASP.NET 2.0 Cookbook from O'Reilly
(http://www.oreilly.com/catalog/aspnetckbk2/)

This works in 2.0. Haven't tried it in 1.1 Maybe it will give you an
idea?

Ken
Microsoft MVP [ASP.NET]
<%@ page language="VB" validaterequest="false" enableviewstate="false" %>

<script runat="server">

Protected Overrides Sub Render _
(ByVal writer As System.Web.UI.HtmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.html"
Dim renderedOutput As StringBuilder = Nothing
Dim strWriter As IO.StringWriter = Nothing
Dim tWriter As HtmlTextWriter = Nothing
Dim outputStream As IO.FileStream = Nothing
Dim sWriter As IO.StreamWriter = Nothing
Dim filename As String

Try
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New IO.StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)

MyBase.Render(tWriter)

'save the rendered output to a file
filename = Server.MapPath(".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(filename, _
IO.FileMode.Create)
sWriter = New IO.StreamWriter(outputStream)
sWriter.Write(renderedOutput.ToString())
sWriter.Flush()
writer.Write(renderedOutput.ToString())
Finally

'clean up
If (Not IsNothing(outputStream)) Then
outputStream.Close()
End If

If (Not IsNothing(tWriter)) Then
tWriter.Close()
End If

If (Not IsNothing(strWriter)) Then
strWriter.Close()
End If
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Capture Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem>red</asp:listitem>
<asp:listitem>blue</asp:listitem>
<asp:listitem>green</asp:listitem>
</asp:dropdownlist></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text
of itself. Can this be done? I have tried looping through all my
controls and rendering them as per your example but am hitting some
walls.

Any ideas?

Kind Regards

Ray Booysen
--
Ray Booysen
rj********@rjb.za.net


--
Ray Booysen
rj********@rjb.za.net

Mar 1 '06 #5
Woops, my mistake... I'll let you know.

Ken Cox - Microsoft MVP wrote:
It's Ken, not Kevin, but let us know how it works for you?

Ken

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
Hi Kevin.

I'll give it a shot. Thanks!

Ken Cox - Microsoft MVP wrote:
Hey Ray,

Here's something adapted from ASP.NET 2.0 Cookbook from O'Reilly
(http://www.oreilly.com/catalog/aspnetckbk2/)

This works in 2.0. Haven't tried it in 1.1 Maybe it will give you an
idea?

Ken
Microsoft MVP [ASP.NET]
<%@ page language="VB" validaterequest="false" enableviewstate="false" %>

<script runat="server">

Protected Overrides Sub Render _
(ByVal writer As System.Web.UI.HtmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.html"
Dim renderedOutput As StringBuilder = Nothing
Dim strWriter As IO.StringWriter = Nothing
Dim tWriter As HtmlTextWriter = Nothing
Dim outputStream As IO.FileStream = Nothing
Dim sWriter As IO.StreamWriter = Nothing
Dim filename As String

Try
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New IO.StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)

MyBase.Render(tWriter)

'save the rendered output to a file
filename = Server.MapPath(".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(filename, _
IO.FileMode.Create)
sWriter = New IO.StreamWriter(outputStream)
sWriter.Write(renderedOutput.ToString())
sWriter.Flush()
writer.Write(renderedOutput.ToString())
Finally

'clean up
If (Not IsNothing(outputStream)) Then
outputStream.Close()
End If

If (Not IsNothing(tWriter)) Then
tWriter.Close()
End If

If (Not IsNothing(strWriter)) Then
strWriter.Close()
End If
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Capture Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem>red</asp:listitem>
<asp:listitem>blue</asp:listitem>
<asp:listitem>green</asp:listitem>
</asp:dropdownlist></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text
of itself. Can this be done? I have tried looping through all my
controls and rendering them as per your example but am hitting some
walls.

Any ideas?

Kind Regards

Ray Booysen
--
Ray Booysen
rj********@rjb.za.net


--
Ray Booysen
rj********@rjb.za.net


--
Ray Booysen
rj********@rjb.za.net
Mar 2 '06 #6
Hi Ken

Thanks, works perfectly.

Now the next step is to find a way to add this functionality to call
when required, not every time the page is rendered. The overhead will
be too much if on every render, the page output is stored in memory or
to a file.

Any ideas?

Regards
Ray

Ken Cox - Microsoft MVP wrote:
It's Ken, not Kevin, but let us know how it works for you?

Ken

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
Hi Kevin.

I'll give it a shot. Thanks!

Ken Cox - Microsoft MVP wrote:
Hey Ray,

Here's something adapted from ASP.NET 2.0 Cookbook from O'Reilly
(http://www.oreilly.com/catalog/aspnetckbk2/)

This works in 2.0. Haven't tried it in 1.1 Maybe it will give you an
idea?

Ken
Microsoft MVP [ASP.NET]
<%@ page language="VB" validaterequest="false" enableviewstate="false" %>

<script runat="server">

Protected Overrides Sub Render _
(ByVal writer As System.Web.UI.HtmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.html"
Dim renderedOutput As StringBuilder = Nothing
Dim strWriter As IO.StringWriter = Nothing
Dim tWriter As HtmlTextWriter = Nothing
Dim outputStream As IO.FileStream = Nothing
Dim sWriter As IO.StreamWriter = Nothing
Dim filename As String

Try
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New IO.StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)

MyBase.Render(tWriter)

'save the rendered output to a file
filename = Server.MapPath(".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(filename, _
IO.FileMode.Create)
sWriter = New IO.StreamWriter(outputStream)
sWriter.Write(renderedOutput.ToString())
sWriter.Flush()
writer.Write(renderedOutput.ToString())
Finally

'clean up
If (Not IsNothing(outputStream)) Then
outputStream.Close()
End If

If (Not IsNothing(tWriter)) Then
tWriter.Close()
End If

If (Not IsNothing(strWriter)) Then
strWriter.Close()
End If
End Try
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Capture Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem>red</asp:listitem>
<asp:listitem>blue</asp:listitem>
<asp:listitem>green</asp:listitem>
</asp:dropdownlist></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
Hi All

In my ASP.NET project, all my pages inherit from a base class which
extends the Page object. I also have a pdf generator that takes in HTML
Text and will generate a PDF for you. What I want to implement in my
custom Page class is the ability for the page to generate the HTML text
of itself. Can this be done? I have tried looping through all my
controls and rendering them as per your example but am hitting some
walls.

Any ideas?

Kind Regards

Ray Booysen
--
Ray Booysen
rj********@rjb.za.net


--
Ray Booysen
rj********@rjb.za.net


--
Ray Booysen
rj********@rjb.za.net
Mar 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joel Reinford | last post by:
I am working on an ASP.NET web app. One of the pages will be using several user controls. The controls will be loaded dynamically based on SQL Server data. I need to be able to retrieve the...
15
by: Cognizance | last post by:
I need a solution for the following, if anyone can think of one. :) I have: 1 form on the page. (no name, no id value set.) 3 hidden form elements named: catalog, vwoidc, oid !!! I can only...
1
by: Robin Dindayal | last post by:
Does anyone know how I can print a fully rendered .aspx to the server's printer? I know that, if I wanted to print to the client's printer it would be easy (ie. use javascript's window.print()). ...
4
by: Timo | last post by:
Over the weekend, I am installing a website on a laptop so our sales staff can give a demonstration on Monday at a potential client site. Things are not working as expected. I'm hoping what's wrong...
2
by: | last post by:
Hi All, i need to get the rendered source of a asp.net page. it's not possible at that point to create a http request. - how can i simulate a page load & rendering lifecycle to get the source...
1
by: SlimFlem | last post by:
I hope this makes sense. Here is what I am attempting. I have an inital generic aspx page that has one custom tag: <web:site id=webSite runat=server/> When this control evaluates, it will...
6
by: amaragraps | last post by:
Dear thescripts Experts, I have converted my large wavelets page http://www.amara.com/current/wavelet.html from HTML into XHTML and CSS and have one large remaining bug. On Safari and Opera...
2
by: Iain | last post by:
Hi All Using Delphi 2006 developer - C# Project I have the following 2 event handlers for the datagrid - see botton of page Both events will fire off correctly but i have a problem collecting...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.