问题描述
ASP.NET母版页的内容页面的元素都似乎是具有自己的ID更改或$ P $由ASP.NET页面渲染ppended。
ASP.NET Master Page Content Page's elements all seem to be having their ID's changed or prepended by the ASP.NET page renderer.
这打破了所有的CSS样式在原有基础上元素ID。
This breaks all CSS styles based on the original element IDs.
这是严重的它是如何工作?如果是这样,有没有变通的办法?
Is this seriously how it works? If so, is there a way around it?
推荐答案
是的,你可以指定的ClientIDMode
将其设置为静态。
Yes, you can specify the ClientIDMode
set it to static.
的例子的:
客户端
<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static"></asp:TextBox>
code背后
TextBox txtBox = new TextBox();
txtBox.ID = "TextBox1";
txtBox.ClientIDMode = ClientIDMode.Static
如果设置为静态...
By setting it to static...
的客户端ID值被设置为ID属性的值。如果控制是一个命名容器时,控制被用作命名容器为任何控制,它包含的层次结构的顶部。
更新 感谢的@克里斯生动的的附加信息的
Update thanks to @Chris Lively for the additional info
页面级
<%@ Page Language="C#" ClientIDMode="Static" AutoEventWireup="true"...
应用级
<system.web>
<pages clientIDMode="Static"></pages>
</system.web>
的引用的:
-
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx
http://beyondrelational.com/blogs/hima/archive/2010/07/16/all-about-client-id-mode-in-asp-net-4.aspx
这篇关于ASP.NET母版页内容页的标识基于原始元素ID一切都变了,打破CSS?你在跟我开玩笑吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!