<asp:Textbox runat="server" Id="Username" />
This might render as:
<input type="text" id="ctl00_mainContent_Username" />
But in web.config if I do:
<pages clientIDMode="Static">
This renders as:
<input type="text" id="Username" />
I’ve gone for the second option, so client ID’s are simpler and not dynamic, meaning I can have all my Javascript external because I don’t need to use Username.ClientID.
But why is it designed this way? Why does it give weird names to stuff? The second way just seems easier to work with.
It’s decorating IDs so that there will never be duplicate IDs on a page even if you use that bit of server-side markup several times on one page.
Like most ‘decorate this name automatically so that a duplicate can never occur’ schemes, the name ends up long and ugly.
You have to remember that the original concept of ASP.NET was that nobody would ever look at the output HTML or care about details like IDs, because all that was abstracted away for you. So a simple, ugly, name decoration scheme would be fine – it was just an internal implementation detail.