加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在asp.net中使用前缀’ct100’更改控件ID

发布时间:2020-12-16 03:59:21 所属栏目:asp.Net 来源:网络整理
导读:检查我的页面控件ID就像 – ContentPlaceHolder1_lnkDistributors. 但是,在实时服务器中托管我的网站后,Prefix正在添加到上面的ID. 喜欢:ctl00_ContentPlaceHolder1_lnkDistributors. asp:LinkButton ID="lnkDistributors" runat="server" Text="Distributo
检查我的页面控件ID就像 – ContentPlaceHolder1_lnkDistributors.

但是,在实时服务器中托管我的网站后,Prefix正在添加到上面的ID.

喜欢:ctl00_ContentPlaceHolder1_lnkDistributors.

<asp:LinkButton ID="lnkDistributors" runat="server" Text="Distributors">
</asp:LinkButton>

请帮我.
谢谢Adv.

解决方法

静态ClientIDMode用于控制HTML中的ID;但你必须小心使用它:它不能保证页面中控件ID的唯一性.

<asp:LinkButton ID="lnkDistributors" ClientIDMode="Static"  
 runat="server" Text="Distributors">  </asp:LinkButton>

如果您的控件的ClientIDMode设置为AutoID,则控件的ID将具有一个前缀以使其唯一. (例如,ID为“sam”的控件将变为“ct100_sam”).
如果您的控件将其ClientIDMode设置为Static,则不会更改ID并保持开发人员将其设置为的内容.

MSDN

ASP.NET为如何生成ClientID属性值提供了多种算法.您可以通过设置其ClientIDMode属性来选择要用于控件的算法.算法由以下列表中列出的ClientIDMode枚举值标识.

AutoID

The ClientID value is generated by concatenating the ID values of each parent naming container with the ID value of the
control. In data-binding scenarios where multiple instances of a
control are rendered,an incrementing value is inserted in front of
the control’s ID value. Each segment is separated by an underscore
character (_). This algorithm was used in versions of ASP.NET earlier
than ASP.NET 4.

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.

Predictable

This algorithm is used for controls that are in data-bound controls. The ClientID value is generated by concatenating
the ClientID value of the parent naming container with the ID value of
the control. If the control is a data-bound control that generates
multiple rows,the value of the data field specified in the
ClientIDRowSuffix property is added at the end. For the GridView
control,multiple data fields can be specified. If the
ClientIDRowSuffix property is blank,a sequential number is added at
the end instead of a data-field value. This number begins at zero and
is incremented by 1 for each row. Each segment is separated by an
underscore character (_).

Inherit

The control inherits the ClientIDMode setting of its NamingContainer control. The default value of ClientIDMode for a page is Predictable. The default value of ClientIDMode for a control is Inherit. Because the default for controls is Inherit,the default generation mode is Predictable. (However,if you use Visual Studio to convert a Web project to ASP.NET 4 from an earlier version,Visual Studio automatically sets the site default to AutoID in the Web.config file.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读