What is ct100 and how do I rename it?

2020-07-09 02:27发布

问题:

Working in .net 4.0, it still seems all my input controls have the attribute 'name', with a value that begins 'ct100$...'.

Is there any way to rename this?

I've gone all the way up the control hierarchy, and given each control an ID and set its clientidmode to 'Static' to no avail, even the 'earliest' controls on the page still inherit the prefix.

回答1:

This is the master page's ID. I change it by adding a Page_Init to my masterpage which sets its id:

Private Sub InitSub(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    ID = "master"
End Sub

This ID is normally empty/null so when it renders it it generates an id (starting at ct100 and going up)

Like @Scott Stafford said, keep it short because it prefixes every client id on your page.

I use words like "mBio", "mHome", etc..



回答2:

Why rename it? You can, as @Bob Fincheimer describes, but so what? Also, if you DO rename it, keep the new name short, because that name shows up in all generated HTML and all POSTing variables hundreds of times, possibly enough to actually affect performance of your site.



回答3:

If you want to remove it, look in your web.config for the following tag:

<system.web>
    ...
    <pages ... clientIDMode="*something*">
    </pages>
    ...
</system.web>

Remove the clientIDMode="something" property specification. Just take it out.

** I stole my own answer from here.



标签: asp.net