Reputation: 11615
Is there a way to disable the ASP.Net auto-naming?
For instance: When I have a control on my page that sits inside a masterpage instead of being named
theLabel
it is renamed to
ctl00_ContentPlaceHolder1_clist0_rptSelected_ctl05_theLabel
This is the behavior I don't want.
Upvotes: 2
Views: 1339
Reputation: 18549
If you're using ASP.NET 4.0 then yes you can.
Otherwise, it's difficult. If you want the client id in javascript you can do something like this::
<script type="text/javascript">
function DoSomething(){
alert('<%= Control.ClientID %>');
}
</script>
Upvotes: 1
Reputation: 34810
This is a common headache with ASP.NET. If ASP.NET 4 is an option for you, you can use the new ClientID functionality to customize the naming convention.
More information, courtesy of The Gu:
Upvotes: 5
Reputation: 51166
If you're lucky enough to be able to target ASP.NET 4.0...
In your page directive, set ClientIDMOde="Static"
. This will emit ID's exactly as you have them in your controls.
So if you have:
<asp:Label ID="example" runat="server" />
It will emit this clean ID:
<span id="example">something...</span>
Upvotes: 4