HtmlGenericControl("a") vs. HtmlAnchor
I was looking into why one of my applications w开发者_如何学Pythonas running quite slowly. The application generates and displays a grid and populates it with work tasks (rendered as table cells). Inside each task there is an <a href="...
which brings up some more info about the task.
As this is all built up dynamically from the codebehind, I've used HTMLTableRows/Cells
to create the rows and cells, then used the Controls
properties to add HTMLAnchors
. Whenever I'm setting attributes I've used HTMLAnchor.HRef
, HTMLTableCell.ColSpan
, etc.
I noticed that if I use the generic HTMLGenericControl
and then use its Attributes
collection, e.g.
HTMLGenericControl a = new HTMLGenericControl("a");
a.Attributes["href"] = task.getLink();
it runs significantly quicker than what I would have thought is the preferred way of doing the same thing:
HtmlAnchor a = new HTMLAnchor;
a.HRef = task.getLink();
Does anyone have any explanation for where this apparent extra 'overhead' comes from?
EDIT
In case anyone is confused by my explanation, I posted another question for the same project, which has a screenshot.
@subkamran I had the same thought, but after looking it up, actually both HTMLAnchor
and HTMLGenericControl
are sub-classed from the same parent: HTMLContainerControl
. One significant difference is that HTMLAnchor implements the IPostBackEventHandler
to handle the "ServerClick" event. This surely adds something to the slowness ...
精彩评论