How to retrieve HTML in ASPX page

N

naz

Hello,

Is it possible to retrieve the HTML which gets dynamically created in
an ASPX file and presented to the client? I need to do this from the
server.

Thanks

Naz
 
K

Konrad Rotuski

you mean dynamically generating allhtml ?

Response.Clear
set conent type to text/html (Response.AddHeader AFAIR)
write to response stream, close it

HTH
 
J

John Timney \(Microsoft MVP\)

try this

StringWriter sw;
HtmlTextWriter htmltw;
sw = new StringWriter();
htmltw = new HtmlTextWriter(sw);
base.Render(htmltw);
StringBuilder temp = sw.GetStringBuilder();


--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
 
N

naz

Hi John

Thanks for your help. I tried using your code:
StringWriter sw;
HtmlTextWriter htmltw;
sw = new StringWriter();
htmltw = new HtmlTextWriter(sw);
base.Render(htmltw);
StringBuilder temp = sw.GetStringBuilder();

But when it tries to render the html, I get the following error:

"A page can have only one server-side Form tag. "

and:

"Exception Details: System.Web.HttpException: A page can have only one
server-side Form tag."

I do have only 1 Server Side Form Tag! And I tried reading about
base.Render in MSDN with little luck.

Any ideas why I'm getting this error on Render?

Thanks and Regards

Naz
 
N

naz

Hi Konrad,
you mean dynamically generating allhtml ?

I need to get the HTML that was dynamically generated in an ASPX page.
Response.Clear
set conent type to text/html (Response.AddHeader AFAIR)
write to response stream, close it

Thanks for the advice but can you show me an example? I am having
difficulty finding an example (or documentation) that will allow me to
retrieve the HTML content of an aspx page after it is dynamically
built. This is all new to me!

Thanks

Naz
 
R

Rajesh.V

I can think of a very simple way to get the html. i.e. create a httprequest
(programmatic page request). And out comes the html in the response.
 
N

naz

Hello,

I got it working. In case anyone is interested, here is the code:

-----------------------------------------------------------------------
string path = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;//.FilePath;

HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create(path);


loHttp.Timeout = 10000; // 10 secs
loHttp.UserAgent = "Code Sample Web Client";

loHttp.CookieContainer = new CookieContainer();

HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse();

Encoding enc = Encoding.GetEncoding(1252); // Windows-1252 or iso-
if (loWebResponse.ContentEncoding.Length > 0)
{
enc = Encoding.GetEncoding(loWebResponse.ContentEncoding);
}

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream(),enc);

string html = loResponseStream.ReadToEnd();

loResponseStream.Close();
loWebResponse.Close();
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top