Just written a quick little custom control, decended from Label, with an
extract bool property NeedHtmlEncode, that will automatically HTML encode
the Text property.
In the Render method, I can't just use HttpUtility.HtmlEncode(Text) because
it won't deal with fonts, bold etc etc. So I wrote the following bodge to
set the Text property with the encoded value, render as normal, then reset
Text back to it's original value.
I'm sure there is a better way, can anyone help?
Thanks,
John
protected override void Render(HtmlTextWriter output)
{
if (needHtmlEncode)
{
string s = Text;
try
{
Text = System.Web.HttpUtility.HtmlEncode(Text);
base.Render(output);
}
finally
{
Text = s;
}
}
else
// normal, without encoding
base.Render(output);
}
Showing posts with label practice. Show all posts
Showing posts with label practice. Show all posts
Monday, March 26, 2012
Thursday, March 22, 2012
HTML Controls vs Web Controls
Is there a cut and dry or "best practice" answer for when to use straight HTML, the HTML controls (runat=server), or the web controls?
Thanks!You could have a look here:
ASP.NET Server Controls Recommendations
and here, perhaps:
Introduction to ASP.NET Server Controls
Thanks!!!
Subscribe to:
Posts (Atom)