Question

Here is my markup:

<input type="hidden" runat="server" name="block" id="FSC_show_sidebar_button" value="0" />
<input type="hidden" runat="server" name="block" id="FSC_hide_sidebar_button" value="1" />

This is what it looks like when the page is rendered and I inspect it:

<input name="ctl00$MainContent$FSC_show_sidebar_button" id="ctl00_MainContent_FSC_show_sidebar_button" type="hidden" value="0"/>
<input name="ctl00$MainContent$FSC_hide_sidebar_button" id="ctl00_MainContent_FSC_hide_sidebar_button" type="hidden" value="1"/>

Is there a way to keep the 'name' attribute from changing? (Not the ID I do not care if this changes)

Was it helpful?

Solution

Due to the runat="server" attribute, this becomes a server side control. This would prepend your masterpage, control information to your input element.

OTHER TIPS

This is a naming convention that ASP.Net uses to convert the ID property you set to a client ID. You can modify this behavior by setting the ClientIDMode property. By default this is set to "Predictable", which means:

The ClientID value is generated by concatenating the ClientID value of the parent naming container with the ID value of the control.

To make ASP.Net use the ID exactly as you specify, set ClientIDMode=Static. You can set this globally in web.config:

<system.web>
    <pages clientIdMode="Static" ... />
</system.web>

Or at the page (or individual control) level:

<%@ Page ClientIDMode="Static" ... %>

This is because your element is inside of a master page, the master page uniquely identifies controls by naming it by containers.

MainContent is the name of your content placeholder.

To avoid this name mangling, then you need to use the ASP.NET 4.0 ClientIDMode attribute.

Read Control.ClientIDMode Property for more information on the ClientIDMode attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top