简体   繁体   中英

HtmlGenericControl(“a”) vs. HtmlAnchor

I was looking into why one of my applications was 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, eg

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM