javascript 在 ASP.NET 中访问控制客户端名称而不是 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5763557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:16:14  来源:igfitidea点击:

Accessing control client name and not ID in ASP.NET

javascriptasp.netonclickclient-side

提问by nima

I want to fire a server-side ASP.NETbutton click event in JavaScript. I checked the page source and the button's onclickin client side is:

我想在 JavaScript 中触发服务器端ASP.NET按钮单击事件。我检查了页面源代码,客户端的button'sonclick是:

WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$LoginInfo1$btnliOK", "", true, "", "", false, false));

But I have to replace ctl00$LoginInfo1$btnliOKwith something like <%= btnliOK.ClientName %>. Is there a way to do that?

但我必须ctl00$LoginInfo1$btnliOK用类似的东西替换<%= btnliOK.ClientName %>。有没有办法做到这一点?

回答by Aristos

You can get it using the Control.UniqueID Property

您可以使用 Control.UniqueID 属性获取它

btnliOK.UniqueID

UniqueIDgives the on page rendered name
ClientIDgives the on page rendered id
IDgive's the id that you can use on code behind

UniqueID给出页面呈现的名称
ClientID给出页面呈现的id
ID给出你可以在后面的代码中使用的 id