当我使用母版页时,为什么我的所有元素都被重命名?
我不明白为什么这很有用。我有一个带有名为 Main 的内容持有者的母版页,并且有一个带有匹配内容标签的内容页。然而,我注意到,当页面放在一起时,我的一些元素的 id 发生了变化,或者我应该说是变态,就像这样:
<input value="fizz-buzz" name="ctl00$Main$options" type="radio" id="Main_foobar"/>
这对我的 css 造成了严重破坏。请帮忙。
I can't understand why this is at all useful. I've got a master page with a content holder called Main, and I've got a content page with a matching content tag. However, I've noticed that when the pages get put together, the ids of some of my elements are changed, or should I say perverted, like so:
<input value="fizz-buzz" name="ctl00$Main$options" type="radio" id="Main_foobar"/>
This is wreaking havok on my css. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是为了确保来自不同来源的多个 ID 始终具有唯一的名称。
在ASP.NET 4.0中,您可以将ClientIDMode设置为静态,并且控件不会被重命名。
This is to ensure that multiple IDs from different sources will always have a unique name.
In ASP.NET 4.0, you can set the ClientIDMode to static and controls won't be renamed.
这就是 ASP.net 中的情况(直到 3.5)。这是为了避免添加到不同内容占位符的控件的重复 ID 和名称。
在 ASP.net 4.0 中,您可以控制控件 Id 的生成方式。
This is the way things are in ASP.net (till 3.5). This is to avoid duplicate ids and names of controls added to different content place holders.
In ASP.net 4.0 you can control how the control Ids are generated.
当您需要自定义 ASP.net 控件的样式时,请始终设置其 CssClass 属性并在样式表中引用它,即使该控件应该是唯一的。类名永远不会改变。
When you need to customize the style of an ASP.net Control, always set its CssClass attribute and refer to it in your stylesheet, even if the control is meant to be unique. Class names never change.
如果你卡在 3.5 上并且无法升级到 4.0,我只是在 codeplex 上放了一个我已经使用多年的解决方案。
http://awesomeclientid.codeplex.com/
几天前才上传,但基本上它序列化了所有您指定到 HTML 文档上的 Json 数组的控件,以便在 JavaScript 中使用。
我在这里写了一篇关于它的快速块文章:
http://www.philliphaydon.com/2010/12/i-love-clean-client-ids-special-with-net-2-0/
您可以注册 HTTPModule ,或者在 PreRenderComplete 上逐页启动并序列化页面,您最终会得到文档中的 JavaScript 块,其内容如下:
然后,当您编写 JavaScript 时,您可以执行以下操作:
If you are stuck on 3.5 and can't upgrade to 4.0, I just put a solution on codeplex that I've been using for years.
http://awesomeclientid.codeplex.com/
Only just uploaded it a few days ago but basically it serializes all the controls that you specify to a Json array on the HTML doc for use in JavaScript.
I wrote a quick block post about it here:
http://www.philliphaydon.com/2010/12/i-love-clean-client-ids-especially-with-net-2-0/
You can either register the HTTPModule, or instinciate and serialize the page on PreRenderComplete on a page-by-page basis, what you will end up with is a JavaScript block in your doc looking along the lines of:
Then when you wrote your JavaScript you can do: