CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 3/11/2004 7:26:54 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 2 Views: 85 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
3 Items, 1 Pages 1 |< << Go >> >|
phobosjr
Asp.Net User
How do you capture HTML output of an aspx page or server control?3/11/2004 7:26:54 AM

0/0

This is probably a really simple question to answer but here it is: How do you capture the HTML output of a server control before it is outputted to the page? In fact how do you capture the HTML that an aspx page outputs before it is written to the page?

The only way I can think of doing this is to inherit from the System.Web.UI.HtmlTextWriter class that is used by the page and then over ride virtually every write method in that class. Now in the overridden methods I can save the in coming string to a file? as you can see it is getting very complicated and I know that there is a better way ?

For those interested here is some code showing how to use a custom HtmlTextWriter:

using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CustomControls
{
public class MyPage : Page
{
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new MyHtmlTextWriter(writer);
}
}


public class MyHtmlTextWriter: HtmlTextWriter
{
private TextWriter writer;
public MyHtmlTextWriter(TextWriter writer): base(writer)
{
this.writer = writer;
}

public MyHtmlTextWriter(TextWriter writer, string tabString): base(writer, tabString)
{
this.writer = writer;
}

public override void RenderBeginTag(HtmlTextWriterTag tagKey)
{
base.RenderBeginTag(tagKey);
}
}

}

The code above was taken from the .NET Framework Class Library,
HtmlTextWriter Constructor [C#]
joteke
Asp.Net User
Re: How do you capture HTML output of an aspx page or server control?3/11/2004 8:43:50 AM

0/0

Hi,

basically Page does not like that its RenderControl is called more than once (that is managed internally in its OnFormRender render method). But you can get over it something like this:


System.IO.StringWriter swriter=new System.IO.StringWriter();
HtmlTextWriter hwriter=new HtmlTextWriter(swriter);
Page.RenderControl(hwriter);

//As an example write the HTML out
Response.Write(Server.HtmlEncode(swriter.ToString()));
swriter.Close();


Then just override Page's own Render method to prevent duplicate rendering (its not really an issue, but prevented internally by the Page as part of preventing duplicate server-side forms)

protected override void Render(HtmlTextWriter writer)
{
//Dummy method to prevent page from being normally rendered
}


With only controls this should be easier.
Thanks,

Teemu Keiski
Finland, EU
phobosjr
Asp.Net User
Re: How do you capture HTML output of an aspx page or server control?3/18/2004 6:54:10 AM

0/0



Thanks for the help Joteke

The code that you gave works fine ? but you have to iterate through the controls like such:

for( int i=0; i<Page.Controls.Count; i++)
{
Page.Controls[i].RenderControl(hwriter);

}

This solution however only outputs HTML for down level browsers. I wanted to use some of the Java Script that was generated. I tried setting the browser version to Internet Explorer 5.5 but the html still remained the same (I could not find the option that would have explicitly set Java Script to ?ON?)! Is there any way to make the page believe that it is rendering to an Internet Explorer browser that is Java Script enabled?

Thanks in advance?

3 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
ASP.NET by Example Authors: Steven A. Smith, Pages: 552, Published: 2002
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Pro ASP. Net 3. 5 Server Controls and AJAX Components Authors: Rob Cameron, Dale Michalk, Pages: 740, Published: 2008
Pro ASP.NET 3.5 in C# 2008 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1498, Published: 2007
Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional Authors: Matthew MacDonald, Pages: 954, Published: 2007
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Visual Basic.Net by Example Authors: Gabriel Oancea, Robert P. Donald, Pages: 976, Published: 2002
Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages Authors: Jacob J. Sanford, Pages: 474, Published: 2007

Web:
How do you capture HTML output of an aspx page or server control ... How do you capture HTML output of an aspx page or server control? Last post 03- 18-2004 3:59 AM by phobosjr. 2 replies. Sort Posts: ...
A Simple ASP.NET Server Control: Message Box & Confirmation Box ... NET, each ASPX page only supports one web form server control, .... / // The HTML writer to write out to protected ...
Capturing Output from ASP.Net Pages - Rick Strahl's Web Log One question I frequently see asked is how to capture output in ASP. ..... I want only the page itself. Of course Server.Execute("/myPage.aspx") catches the ...
Managing ASP.NET Navigation | O'Reilly Media To capture the output from an ASPX page and display it at a specified location on another ASPX page, use Server.Execute . If valid HTML output is essential, ...
Output ASP.NET Page to HTML Is it possible to capture the html and save it for later use. ... Text.Encoding. ASCII). Output of the .aspx and the html generated is shown below: ...
Difference between web control, server control and Html control An output of an ASP .NET server control can be the result of many HTML ... to capture the event rasied by winform UserControl in html page ? ...
Cutting Edge: The Client Side of ASP.NET Pages The .aspx page contains three server controls: a textbox to capture data, ... Figure 3 shows the HTML output for the sample page in Figure 1. ...
Capturing the HTML from an ASP.NET 2.0 page - microsoft.public ... NET 2.0 but capture the HTML output. ... It doesn't work if I include a server- side dropdownlist control on the page. ...
Server Control Basics There isn’t a form server control in HelloWorld.aspx, because it is a content page that. renders within a master page, which is where the HTML form exists. ...
how to capture the chart control output ? - .NET ASP To produce 1 dynamic chart, I add a control to my aspx page positioned in ... to capture the chart control output so it can be complemented with table tags. ...




Search This Site:










secure ftp

setting the location of ...

template control inside repeater.

how to expose a property for a dynamically built control?

using the url/params object to store state in a custom control

metabuilders rowselectorcolomn for .net 1.0 wanted

web custom controls - calling control

hosting sharepoint server 2007

callback question in vs2005 april ctp

session variable as custom control problem...

problem with datagrid checkbox column checkedchange event

http://www.freewebdot.com/

.net 3.5 hosting requirements

calendarpopup component

any reasons to stay clear of [www.planetsmb.com]

looking for a good tutorial

reliablesite.net - :( so far not too good

how to host an asp.net 2.0 website on 2003 server iis 6.0

adding a textbox in a table

design time error with arraylist property

custom datagridcolumn

render won't render...

why is the control rendering a property as an attribute?

problem: sample of htmltextwriter class

connecting to outlook

don't use global internet solutions as web hoster

a customed tab control

programmatically adding/removing controls at design time

extending the asp:literal control

runtime exception with enumconverter

  Privacy | Contact Us
All Times Are GMT