Loading...
DotNetKicks.com
.NET links, community driven
login
register
submit a story
upcoming stories
about
blog
Why not
join our community?
, there are
11 users online
home
users
aquinas
comments
DotNetKick.com is an
open-source project
. Please
report any bugs
and let us know
your great suggestions
.
Currently running svn revision
620
(rss)
Kick Spy!
,
Kick Zeitgeist
and
Kick Widgets
aquinas
Profile
Kicked
Submitted
Comments
Tags
Friends
Kicked By Friends
Submitted By Friends
Comments:
C# HTML Helper Class
Well, you stated that "There is more overhead associated with HTMTextWriter." That's why I included the timings, so that those who might wish to use your code were aware that their did not appear to be any significant overhead as far as time goes. If you meant some other overhead besides time, then sorry, my bad.
posted by
aquinas
7 months, 5 days ago
C# HTML Helper Class
try this:
System.Diagnostics.Stopwatch stopw = new System.Diagnostics.Stopwatch();
stopw.Start();
for (int i = 0; i < 1000; i++) {
System.Text.StringBuilder sb = new StringBuilder();
List<ElementAttribute> attributes = new List<ElementAttribute>();
attributes.Clear();
attributes.Add(new ElementAttribute(HTMLHelper.ID, "gallery"));
//attributes.Add(new ElementAttribute(HTMLHelper.CLASS, "\" <hello>blah</hello>"));
attributes.Add(new ElementAttribute(HTMLHelper.CLASS, "whatever"));
attributes.Add(new ElementAttribute("onclick", "whatever()"));
for (int j = 0; j < 1000; j++) {
sb.Append(HTMLHelper.BeginDiv(attributes));
sb.Append("blah");
sb.Append(HTMLHelper.EndDiv());
}
}
stopw.Stop();
Console.WriteLine(stopw.ElapsedMilliseconds);
stopw.Reset();
stopw.Start();
for (int i = 0; i < 1000; i++) {
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(sw);
for (int j = 0; j < 1000; j++) {
writer.AddAttribute(HtmlTextWriterAttribute.Id, "gallery");
//writer.AddAttribute(HtmlTextWriterAttribute.Class, "\" <hello>blah</hello>");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "whatever");
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "whatever()");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write("blah");
writer.RenderEndTag();
//string tstring = sw.GetStringBuilder().ToString();
}
}
stopw.Stop();
Console.WriteLine(stopw.ElapsedMilliseconds);
Console.ReadLine();
On my machine the version that uses HtmlTextWriter is about 300 milliseconds FASTER. If you uncomment out the lines that are commented out, it's about 100 ms slower. The reason why it's slower is because it properly esacapes HTML entities, which the HTMLHelperClass does not. That's what [)amien was referring to when he said your version is open to HTML injection.
I'm not trying to rail against you. I just take exception with your comment of "After reading these comments I am realizing that it is the tendency of most developers to over-complicate almost everything." It just seems a bit odd that you're saying people over complicate things, when there is an existing class that does what your class does, but you've invented your own. AND you have to tell people that use it to be careful because you need to do your own html escaping.
posted by
aquinas
7 months, 5 days ago
C# HTML Helper Class
Why not HtmlTextWriter?
posted by
aquinas
7 months, 6 days ago
Create Windows Services That Can Install Themselves
Try:
http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx
posted by
aquinas
10 months, 10 days ago
Visual Studio 2008 RTM available for download
Microsoft's website doesn't say anything...
posted by
aquinas
10 months, 26 days ago
The Gospel of the GUID - And Why It Matters!
Regarding making a round trip to the database: what kind of database would one be using that doesn't support identity fields or sequences that you have to make a round trip to the database to get the next id? Please tell me you're not doing a select max(id)+1 from table. Hello race conditions.
"Reason 3: Type/Table Ignorance" Yeah, now you also don't get any foreign key constraints / cascading deletes on your "ParentGUID".
posted by
aquinas
11 months, 9 days ago
Visual Studio 2008 to RTM in Movember
Movember! Mo Visual Studio!
posted by
aquinas
11 months, 10 days ago
Regions == Evil
? Regions == Evil
False
Maybe he meant to assign Evil to Regions, rather than comparing them? =)
posted by
aquinas
11 months, 14 days ago
How to work with drop down lists without using the view state
Just databind in oninit.
posted by
aquinas
11 months, 24 days ago
.NET Framework 3.5 Is Shared Source
*blink*
posted by
aquinas
1 year ago
Convert Relative Paths to Absolute Using Regular Expressions
The code is wrong.
It will not output
img src="http://www.nontalk.com/images/dot.gif, it will output img src="http://www.nontalk.com/mages/dot.gif because it says: match src|href followed by any character that is not h, t, or p. If the url started with h or t or p, the regex wouldn't match at all. I think he wanted a negative lookahead rather than a negated character class. E.g., (?!http)
posted by
aquinas
1 year, 1 month ago
« Previous
1
2
Next »
Sponsored Link:
www.carlist.ie
Search:
Ads via The Lounge
DotNetKicks is an open source project from
Incremental Systems