And inside of it are several " /> And inside of it are several " /> And inside of it are several "/>

Is there a way to prevent the contentplaceholder's ID from affecting child ID's in ASP.NET?

1.6k Views Asked by At

If I have a placeholder that looks like this:

<asp:contentplaceholder ID="Body" runat="server"></asp:contentplaceholder>

And inside of it are several other elements that are runat="server" with ID properties, then I get something like this:

<span id="Body_T966DB943018">
  <div id="Body_T966DB943007_ctl00_ctl00_main"></div>
</span>

Is there a way to set up my contentplaceholder such that the output appears like this:

<span id="T966DB943018">
  <div id="T966DB943007_ctl00_ctl00_main"></div>
</span>

(notice the lack of the "Body_" in all generated IDs)


If you want to know why I'm asking...

I am using Sitefinity. By default, you can set up templates in a back end GUI. This was how the site was originally constructed.

The latter HTML structure is how the CMS has generated templates on the page. Initial construction of CSS and JS used these generated ID's. Now we have added a master template file, and we need to put a default contentplaceholder for Sitefinity's content.

I need to find a way to have this default placeholder (shown above with ID="Body" to not affect the ID's of its children.

2

There are 2 best solutions below

3
mason On

If you want to change the behavior for the entire site you can do it in web.config by setting the ClientIDMode.

<configuration>
  <system.web>
    <pages clientIDMode="Static" />
  </system.web>
<configuration>

Or at the page level.

<%@ Page ClientIDMode="Static" %>

Or at the individual control level.

<asp:Label runat="server" ClientIDMode="Static" />

Keep in mind you'll need to ensure your Client ID's are unique to avoid conflicts.

3
Jon R. On

It would be better to redo your CSS and more appropriate as you can see it is very difficult to maintain those Ids