gpt4 book ai didi

asp.net - 如何阻止 ASP.NET 更改 ID 以使用 jQuery

转载 作者:行者123 更新时间:2023-12-03 21:27:04 25 4
gpt4 key购买 nike

我的网页中有这个标签控件

<asp:Label ID="Label1" runat="server" Text="test"></asp:Label>

当页面呈现时,控件的 id 会更改为这样的内容

  <span id="ctl00_ContentPlaceHolder1_Label3">test</span>

如何阻止 asp.net 更改 ID 以执行这样的 jQuery 操作

$('#label1').html(xml);

最佳答案

简短回答:

设置ClientIDMode=“静态”

<asp:Label ID="myLabel" ClientIDMode="Static" runat="server" Text="testing"></asp:Label>
<小时/>

长答案:

.NET 4 现在可以让您选择 ClientIDMode :

类型:System.Web.UI.ClientIDMode
指示如何生成 ClientID 属性的值。

AutoID
The ClientID value is generated by concatenating the ID valuesof each parent naming container with the ID value of the control. Indata-binding scenarios where multiple instances of a control arerendered, an incrementing value is inserted in front of the control'sID 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. Ifthe control is a naming container, the control is used as the top ofthe hierarchy of naming containers for any controls that it contains.

Predictable
This algorithm is used for controls that are in data-boundcontrols. The ClientID value is generated by concatenating theClientID value of the parent naming container with the ID value of thecontrol. If the control is a data-bound control that generatesmultiple rows, the value of the data field specified in theClientIDRowSuffix property is added at the end. For the GridViewcontrol, multiple data fields can be specified. If theClientIDRowSuffix property is blank, a sequential number is added atthe end instead of a data-field value. This number begins at zero andis incremented by 1 for each row. Each segment is separated by anunderscore character (_).

Inherit
The control inherits the ClientIDMode setting of its NamingContainer control. This is the default.

关于asp.net - 如何阻止 ASP.NET 更改 ID 以使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/497802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com