Name Mangling RRS feed

  • Question

  • User-79945627 posted

    Hi All

    Based on a question I asked in a previous thread where the replies did not give me comfort, I decided to do some research and would like to pass my findings on to this forum as I believe it is important to what you are trying to achieve.

    Name Mangling means ID attributes are altered when master pages are used.

    If I use an ID="name" against some element in a page that is inside a ContentPlaceHolder with an ID="Contents", that is in a master page, the id is changed from "name" to "ctl00_Contents_name" to aid with page uniqness.

    This causes problems for both CSS ID selectors and JavaScript ID hooks.

    Changing ID to class will help resolve the CSS problem but not the JavaScript one.

    The "ctl00_Contents_" will remain constant throughout the page making it easier to reference other elements, "email" becomes "ctl00_Contents_email".

    To maintain accessible XHTML in .Net we could code our web form like this:

    <label accesskey="N" for="ctl00_Contents_name">Name: </label>
    <asp:TextBox ID="name" CssClass="text" tabindex="1" runat="server"></asp:TextBox>

    Which reneders fine as:

    <label accesskey="N" for="ctl00_Contents_name">Name: </label>
    <input name="ctl00$Contents$name" type="text" id="ctl00_Contents_name" class="text" />

    If I had some JavaScript that used code like this:


    To get the process to run correctly we need to modify it to:


    I like to keep all my JavaScript in a separate file (Like we do with our CSS) but if you embed the JavaScript inside the Web form we could use code like this:

    attachBorderAndSelect('<%= name.ClientID %>');

    and for the accessible markup, use this code:

    <label accesskey="N" for="<%= name.ClientID %>">Name: </label>
    <asp:TextBox ID="name" CssClass="text" tabindex="1" runat="server"></asp:TextBox>

    If anyone can improve on this or knows how to disable name mangling I would love to hear from you.

    Bill Wallace

    Tuesday, August 29, 2006 7:08 PM

All replies

  • User-2107136947 posted

    Hi Brave.heart, How about your problem described above ? Have you find the solutions ? Honestly, right now i have the same problem. 


    Wednesday, July 4, 2007 9:06 PM