ASP.NET Master Page Content Page's IDs all changed, breaking CSS based on original element IDs? Are you kidding me

我的梦境 提交于 2019-12-19 03:58:19

问题


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.

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?


回答1:


Yes, you can specify the ClientIDMode set it to static.

examples:

Client Side

<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static"></asp:TextBox>

Code Behind

TextBox txtBox = new TextBox();
txtBox.ID = "TextBox1";
txtBox.ClientIDMode = ClientIDMode.Static

By setting it to static...

The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains.


Update thanks to @Chris Lively for the additional info


Page Level

<%@ Page Language="C#" ClientIDMode="Static" AutoEventWireup="true"...

Application Level

<system.web>
    <pages clientIDMode="Static"></pages>
</system.web>

references:

  • 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




回答2:


I think you need to use the ClientID property instead of the ID property.

Documentation: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx



来源:https://stackoverflow.com/questions/5494130/asp-net-master-page-content-pages-ids-all-changed-breaking-css-based-on-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!