No default IDs here. Move along.
I can hardly believe it has taken me this long, several few years in fact, to discover just how few ASP.NET Web Forms controls need an explicit ID attribute. I mean even the default kind of ID value assigned by the designer, e.g. TextBox4
, Label7
, DropDownList1
and other such abominations; in common or garden data binding scenarios most of these aren’t necessary at all.
This pleases me. It pleases me no end, because I have finally been relieved of my tortuous obsession for reassigning meaningful ID attributes to controls, like renaming TextBox1
to surnameText
, etc. If you have any idea how just seeing those default IDs laying around in markup makes me, read on. If you actually write code against such IDs, you may stop reading though, and step outside to be shot.
I quite by accident discovered I can simply delete most of these. Data bound controls don’t need them and controls that raise events don’t need them. That’s why we have object sender
in our events after all. We can simply delete them when they pop up, and only worry about a meaningful ID if we are going to use it, i.e., if it is really going to be meaningful. It is, however, quite the pain to do this manually every time I create or paste a control (VS is considerate enough that it provides one if you thoughtlessly paste a server-side tag without an ID attribute. Enter the macro!
Every time my eyes are offended by the encroaching masses of default IDs, I run this little baby, and it removes any ID attribute that ends in a number. Yes, there may be some casualties one day, but it is unlikely I will hand-code control IDs that require a numbered ID attribute; collateral damage if you will, but I’m happy to accept that and move on. This Macro code carries no warranties, only warnings, but try it if you, like me, like neat code.
Sub RemoveDefaultIds()
DTE.Windows.Item_
(“{CF2DDC32-8CAD-11D2-9302-005345000000}”).Activate() ‘Find and Replace
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
DTE.Find.FindWhat = ” ID=”".#:z”"”
DTE.Find.ReplaceWith = “”
DTE.Find.Target = vsFindTarget.vsFindTargetFiles
DTE.Find.MatchCase = True
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.SearchPath = “Current Document”
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResults1
Debug.Print(DTE.Find.Execute())
DTE.Windows.Item_
(“{CF2DDC32-8CAD-11D2-9302-005345000000}”).Close() ‘Find and Replace
End Sub
发表评论
k0E7jT wonderful points altogether, you just received
OyiGlS This is very interesting, You are a very skilled blogger. I have joined your feed and look forward to seeking more of your excellent post. Also, I ave shared your site in my social networks!
mepiR9 Say, you got a nice article.Really looking forward to read more. Much obliged.
WYjn5k
XzWcjX Very good post.Really thank you! Want more.
yi4c8l Your great competence and kindness in maneuvering almost everything was essential. I usually do not know what I would ave done if I had not encountered such a subject like
lSxEhQ It's hard to seek out educated people on this matter, however you sound like you realize what you're talking about! Thanks
KplhTM Valuable information. Lucky me I found your web site by accident, and I am shocked why this accident didn't happened earlier! I bookmarked it.
8Evfo0 Nice read, I just passed this onto a colleague who was doing a little research on that. And he just bought me lunch since I found it for him smile So let me rephrase that: Thanks for lunch!
M84sxb I do not even know how I ended up here, but I thought this post was good. I don't know who you are but definitely you're going to a famous blogger if you aren't already ;) Cheers!
Im obliged for the blog article.Much thanks again. Fantastic.
I truly appreciate this blog.Much thanks again. Great.
Very good blog post.Thanks Again. Great.
Thanks so much for the blog.Thanks Again. Much obliged.
Im obliged for the post.
I value the blog post.Really thank you! Much obliged.
Thanks for the article.Thanks Again. Want more.
Say, you got a nice blog. Will read on...
Really appreciate you sharing this blog.Really thank you! Keep writing.
Great post.Much thanks again. Really Cool.
I appreciate you sharing this post.Thanks Again. Want more.
Muchos Gracias for your article post. Awesome.
Very good blog.Much thanks again. Great.
Wow, great blog.Much thanks again. Really Cool.
Thanks for sharing, this is a fantastic article post.Thanks Again. Fantastic.
Enjoyed every bit of your blog post. Great.
Appreciate you sharing, great post.Thanks Again. Awesome.
Say, you got a nice article post.Much thanks again. Want more.
I am so grateful for your post.Thanks Again. Awesome.
Thanks for sharing, this is a fantastic article.Thanks Again. Cool.
I cannot thank you enough for the blog post.Really looking forward to read more. Will read on...
Fantastic post.Much thanks again. Awesome.
Very good blog article. Fantastic.
Thank you ever so for you blog post.Much thanks again. Much obliged.
Thanks again for the blog.Really thank you! Will read on...
Appreciate you sharing, great article post.Much thanks again. Really Great.
I am so grateful for your article post.Really looking forward to read more. Great.
Really enjoyed this article post.Really looking forward to read more. Fantastic.
Thank you ever so for you blog.Much thanks again.
Appreciate you sharing, great post.Thanks Again. Great.
Appreciate you sharing, great blog article.Really thank you!
I really like and appreciate your article.Really looking forward to read more. Much obliged.
Really appreciate you sharing this post.Really looking forward to read more. Really Great.
wow, awesome blog post.Really thank you! Keep writing.
Im thankful for the article post.Really looking forward to read more. Cool.
Wow, great post.Much thanks again. Keep writing.
Im thankful for the blog article.Really thank you! Keep writing.
Thank you for your article.Much thanks again. Keep writing.
Great, thanks for sharing this article post.Much thanks again. Much obliged.
Thanks for the blog post. Will read on...