Ask a Question related to ASP.NET Building Controls, Design and Development.
-
cpnet #1
Compress/compact HTML during rendering
I'm writing some custom controls, and I'd like to be able to remove all
unnecessary whitespace, etc. from my output. Ideally, I would just render
as normal, then remove this extra whitespace as the last step in the
rendering process. I'm sure I saw code to do this, but now I can't find it.
Is this something I have to do as I go, or can I somehow do this in a
single, last step of rendering?
Thanks,
cpnet
cpnet Guest
-
Rendering HTML within an InDesign document
Hi all, I'm trying to use InDesign to create User Experience specs for a e-commerce company. Specifically, I want to be able to prototype in a... -
CF 7 rendering HTML differently
I'm reposting this as I now understand the problem better and I can reproduce it. You are going to think I am nuts, but hear me out.....If I save... -
ScrollPane, HTML Rendering with CSS
Alright, so I am loading an swf into the scrollpane with a dynamic textfield as the only content. I am then setting the textfield to render html... -
rendering html from perl
On Friday, Nov 14, 2003, at 02:29 US/Pacific, john@shortstay-london.com wrote: From: drieux Sent: 15 November 2003 17:13 I'm not sure I... -
[Q] HTML rendering?
Hello, Does anyone know if any of the current, cross-platform, GUI toolkits of Ruby has an HTML rendering widget? Cheers, -- Daniel Carrera... -
Steven Cheng[MSFT] #2
RE: Compress/compact HTML during rendering
Hi Cpnet,
As for the problem you mentioned, here is my understanding:
if your custom control is a composite control which use the
"CreateChildControls" to generate the whole controls hierarchy, I think its
ok for use to override the "Render" method and do some modification on the
control's final output. We just need to create HtmlTextWriter through a
StringBuilder and call the
Control's base.Render to get the original Rendered html. Then, we can do
any modification on the stringbuilder as we like. For exmaple:
=====================================
protected override void Render(HtmlTextWriter output)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
HtmlTextWriter writer = new HtmlTextWriter(new System.IO.StringWriter(sb));
base.Render(writer);
//the output has been retrieved in the stringbuilder
//do the modification here
output.Write(sb.ToString());
}
======================================
HOpe helps. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! [url]www.microsoft.com/security[/url]
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
[url]http://msdn.microsoft.com/asp.net/whidbey/default.aspx[/url]
Steven Cheng[MSFT] Guest
-
cpnet #3
Re: Compress/compact HTML during rendering
I thought I remembered there being a property on some class I could set that
would automatically take care of the whitespace removal, but your method
below will work well for me.
Thanks.
cpnet Guest
-
cpnet #4
Re: Compress/compact HTML during rendering
As I looked at this a little more, I think maybe I need to change it a
little in case we end up getting an Html32TextWriter instead of a 'regular'
HtmlTextWriter from the output argument? I also found that if I called
"base.Render( tw)" then the output got rendered twice!
Here's what I came up with as an alternative:
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
object[] createArgs = {new StringWriter(sb)};
//Make sure we're creating an instance of the
//same type of HtmlTextWriter as the original
HtmlTextWriter tw =
(HtmlTextWriter)Activator.CreateInstance(
writer.GetType(), createArgs);
try
{
//Calling base.Render here causes the
//output to be rendered twice?!?
//base.Render( tw);
RenderChildren( tw);
tw.Flush();
//Do stuff to remove whitespace
writer.Write( sb.ToString());
}
finally
{
tw.Close();
}
}
cpnet Guest
-
Steven Cheng[MSFT] #5
Re: Compress/compact HTML during rendering
Hi Cpnet,
Thanks a lot for your followup and your additional suggestions. I really
appreciate. In addition, as for the
===========
"base.Render( tw)" then the output got rendered twice!
===========
problem you mentioned, I'm not sure whether there will be anything else
cause it. I've try both
base.Render(tw) or base.RenderChildren(tw) and didn't encounter this
problem. I simplely add some input controls in my test custom control in
CreateChildControl and they are only rendered once.
Thanks
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! [url]www.microsoft.com/security[/url]
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
[url]http://msdn.microsoft.com/asp.net/whidbey/default.aspx[/url]
Steven Cheng[MSFT] Guest
-
Unregistered #6
Re: Compress/compact HTML during rendering
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
{
base.Render(htmlwriter);
string html = htmlwriter.InnerWriter.ToString();
html = Regex.Replace(html, @"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}", "");
html = Regex.Replace(html, @"[ \f\r\t\v]?([\n\xFE\xFF/{}[\];,<>*%&|^!~?:=])[\f\r\t\v]?", "$1");
html = html.Replace(";\n", ";");
writer.Write(html);
}Unregistered Guest



Reply With Quote

