5

I don't understand it.

The ids of html elements in the master page are changed by the same id but with a prefix and it's breaking the css design.

In the master page I have:

<div id="container" runat="server">

    <asp:ContentPlaceHolder ...

...

The above code is rendered

<div id="ctl00_ctloo_container">

     ...

And the CSS styles are gone obviously.

How do I stop it?

Thanks!

Azhar
  • 20,500
  • 38
  • 146
  • 211
Gaizka Allende
  • 9,228
  • 4
  • 21
  • 16

4 Answers4

4

WebForms should only rewrite the ID's of server controls (like <asp:ContentPlaceHolder />, not ordinary HTML element like <div id="container"> without runat="server"

You cannot prevent the framework from rewriting ID's on server controls. You can use class names instead, though.

JacquesB
  • 41,662
  • 13
  • 71
  • 86
  • Thanks very much to all, in this case I had the runat="server" attributed in the div, Sorry I did not provide it at first time, that's why the Id was changed!! – Gaizka Allende Oct 14 '08 at 07:59
1

AFAIK you cannot do this. This is the default behaviour because of the control tree.

If you would like to use CSS then set the CSS class directly, don't depend on IDs, like

<asp:Whatever runat="server" id="whatever" CssClass="whateverClass">

Update: Here is a similair thread, but it won't help on your CSS problem.

Community
  • 1
  • 1
Biri
  • 7,101
  • 7
  • 38
  • 52
1

Do you need the runat="server" tag? If you do not do anything with the div element in your code-behind, remove it.

-1

I do not need the runat="server" tag and have removed it. Don't know why it was there ... Ids are not changed now. Thanks

Gaizka Allende
  • 9,228
  • 4
  • 21
  • 16