开发者

How does ASP.NET Webforms decide HTML name of a control?

In ASP.NET web forms when a control is rendered on the page, the ID of each field is modified with the ctrl01 as needed to ensure collisions don't happen (aka myField becomes ctrl01$myField or whatnot).

I was wondering where one might find details on HOW the algorithm itself works, or where it might be I can find it. I am assuming the INamingContainer has something to do with this-- but alas I cannot find the part which act开发者_开发百科ually decides the rendered field name.

Any help would be awesome!


You are probably looking for this msdn article.


It's based on the hierarchical layout of the webpage. But you can control this with the ClientId property.

So a textbox in a usercontrol will be named ctrl01#textboxname (Like you said in your post)


It concatenates it's own name with your original id.

In ASP.NET 4 you can suppress this concatenation and keep your own id in three different ways:

  • Each server control has an attribute called clientIdMode which you can set to Static
  • You can also set clientIdMode in the page directive which will affect all controls on the page.
  • Or you can set it in the web.config to affect all controls in all pages. (Unless the page or control is set to a different clientIdMode

Note: If you are using AJAX Control Toolkit you will need to set those controls that are part of the toolkit to a clientIdMode of Predictive


Apart from the other answers, if you are using ASP .NET 4, you have much more control over it.

Take a look @ these web pages

http://www.west-wind.com/weblog/posts/54760.aspx

http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜