adding runat=“server” changes the behaviour of the layout

前端 未结 3 943
盖世英雄少女心
盖世英雄少女心 2021-01-03 00:29

I have a page with some controls, usercontrols etc.

when I change a div from plain

to a
3条回答
  •  不知归路
    2021-01-03 01:08

    When you add runat="server" to a div, the system automatically generates the ID for it. It's referred to as ID mangling. Unfortunately there isn't much that you can do in the 2.0 framework for divs that I'm aware of (without it being a pain anyway), but in 4.0 we're getting an override... On custom controls though (in 2.0) you can override the ClientID and UniqueID fields. So if you created a MyDiv class that used the div as a base and then created the ClientID/UniqueID fields you should be ok.

    Your other option would be to update your CSS/javascript to use the mangled ID. It's fairly static based on the position within the page as ASP.Net uses it to find a control during postback.

提交回复
热议问题