473,549 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1249
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.H tmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.h tml"
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(t Writer)

'save the rendered output to a file
filename = Server.MapPath( ".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(f ilename, _
IO.FileMode.Cre ate)
sWriter = New IO.StreamWriter (outputStream)
sWriter.Write(r enderedOutput.T oString())
sWriter.Flush()
writer.Write(re nderedOutput.To String())
Finally

'clean up
If (Not IsNothing(outpu tStream)) Then
outputStream.Cl ose()
End If

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Captur e Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownli st id="DropDownLis t1" runat="server">
<asp:listitem>r ed</asp:listitem>
<asp:listitem>b lue</asp:listitem>
<asp:listitem>g reen</asp:listitem>
</asp:dropdownlis t></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@ rjb.za.net> wrote in message
news:uZ******** ******@TK2MSFTN GP11.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.H tmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.h tml"
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(t Writer)

'save the rendered output to a file
filename = Server.MapPath( ".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(f ilename, _
IO.FileMode.Cre ate)
sWriter = New IO.StreamWriter (outputStream)
sWriter.Write(r enderedOutput.T oString())
sWriter.Flush()
writer.Write(re nderedOutput.To String())
Finally

'clean up
If (Not IsNothing(outpu tStream)) Then
outputStream.Cl ose()
End If

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Captur e Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownli st id="DropDownLis t1" runat="server">
<asp:listitem>r ed</asp:listitem>
<asp:listitem>b lue</asp:listitem>
<asp:listitem>g reen</asp:listitem>
</asp:dropdownlis t></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@ rjb.za.net> wrote in message
news:uZ******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP10.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.H tmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.h tml"
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(t Writer)

'save the rendered output to a file
filename = Server.MapPath( ".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(f ilename, _
IO.FileMode.Cre ate)
sWriter = New IO.StreamWriter (outputStream)
sWriter.Write(r enderedOutput.T oString())
sWriter.Flush()
writer.Write(re nderedOutput.To String())
Finally

'clean up
If (Not IsNothing(outpu tStream)) Then
outputStream.Cl ose()
End If

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Captur e Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownli st id="DropDownLis t1" runat="server">
<asp:listitem>r ed</asp:listitem>
<asp:listitem>b lue</asp:listitem>
<asp:listitem>g reen</asp:listitem>
</asp:dropdownlis t></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@ rjb.za.net> wrote in message
news:uZ******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP10.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.H tmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.h tml"
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(t Writer)

'save the rendered output to a file
filename = Server.MapPath( ".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(f ilename, _
IO.FileMode.Cre ate)
sWriter = New IO.StreamWriter (outputStream)
sWriter.Write(r enderedOutput.T oString())
sWriter.Flush()
writer.Write(re nderedOutput.To String())
Finally

'clean up
If (Not IsNothing(outpu tStream)) Then
outputStream.Cl ose()
End If

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Captur e Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownli st id="DropDownLis t1" runat="server">
<asp:listitem>r ed</asp:listitem>
<asp:listitem>b lue</asp:listitem>
<asp:listitem>g reen</asp:listitem>
</asp:dropdownlis t></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@ rjb.za.net> wrote in message
news:uZ******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP10.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.H tmlTextWriter)
Const OUTPUT_FILENAME As String = "renderedpage.h tml"
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(t Writer)

'save the rendered output to a file
filename = Server.MapPath( ".") & "\" & OUTPUT_FILENAME
outputStream = New IO.FileStream(f ilename, _
IO.FileMode.Cre ate)
sWriter = New IO.StreamWriter (outputStream)
sWriter.Write(r enderedOutput.T oString())
sWriter.Flush()
writer.Write(re nderedOutput.To String())
Finally

'clean up
If (Not IsNothing(outpu tStream)) Then
outputStream.Cl ose()
End If

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Captur e Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownli st id="DropDownLis t1" runat="server">
<asp:listitem>r ed</asp:listitem>
<asp:listitem>b lue</asp:listitem>
<asp:listitem>g reen</asp:listitem>
</asp:dropdownlis t></div>
</form>
</body>
</html>

"Ray Booysen" <rj***********@ rjb.za.net> wrote in message
news:uZ******** ******@TK2MSFTN GP11.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
1900
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 values from the individual fields in those user controls. So far I am not able to access the controls at postback. Any suggestions would be...
15
1541
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 include the javascript right after the body tag. The form is found near the end of the loaded page.
1
4258
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()). However, I need to print to the server's printer. I need to print the fully rendered .aspx page from the codebehind .aspx.cs page to the server's...
4
1308
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 will be apparent from the symptoms below. I created a virtual directory beneath the Default Web Site using the wizard. I have set the execute...
2
1572
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 that would be posted to client... thank you! ingo
1
1119
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 return a small amount of Html with another custom control tag inside this html. For example:
6
2367
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 and the Linux Red Hat browser, the full page is not rendered, even though if you "view" the source in the browser window, all of the text is listed.
2
1975
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 the correct data in teh Update event - I have noted the problem in the event handler
0
3371
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 within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.