添加RUNAT ="服务器"改变了布局的行为 [英] adding runat="server" changes the behaviour of the layout
问题描述
我有一些控件,用户控件等页面。
I have a page with some controls, usercontrols etc.
当我改变从纯&LT一个div; DIV ID =foo的>
到< DIV ID =foo的RUNAT =服务器>
布局完整的变化。
when I change a div from plain <div id="foo">
to a <div id="foo" runat="server">
the layout complete changes.
这是为什么,以及如何我可以prevent呢?
why is that and how can I prevent it?
我使用.NET Framework 2.0的
I'm using 2.0 .NET framework
是因为.NET改变了我的身份证,这显然我不想要?
Is it because .NET changes my id, which obviously I don't want?
推荐答案
如果你在打靶CSS股利控件的ID,然后运行在服务器上的控制,你会发现它不再适用的风格。
If you're targetting the ID of the div control in CSS and then running the control at server, you'll find it no longer applies the style.
这是因为ASP.NET有一个内置的机制(作INamingContainer),以确保比你不能有多个控制同名做。它让你最终加入容器prefixes做到这一点:
This is because ASP.NET has a built in mechanism (INamingContainer) to ensure than you don't have multiple controls named the same. It does this by adding container prefixes so you end up with:
<div id="ctl00_ctl00_myDivName" runat="server" />
解决这个问题的最简单的方法是将其从上一个ID的工作变成一个类工作:
The easiest way around this is to change it from working on an ID to working on a class:
<div class="myDiv" runat="server"></div>
另外,我认为,XHTML要求的div已关闭标签,以便用
Alternatively, I believe that XHTML requires that Divs have closing tags so use
<div runat="server">Some content</div>
这篇关于添加RUNAT =&QUOT;服务器&QUOT;改变了布局的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!