如何找到控制客户端ID [英] how to find control client id
本文介绍了如何找到控制客户端ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面,btnBook1是服务器按钮控件ID。只是我想访问这个button.btnBook1的客户端id动态存在。所以当按钮不存在时,这行代码返回error.please提供了一种方式,所以我可以访问控件的客户端ID。
var str = jquery(#<%= btnBook1.ClientID%>)。attr(id)。toString();
请尽快提供解决方案。
提前谢谢
In below btnBook1 is a server button control id. just i want to access client id of this button.btnBook1 exists dynamically.so when button does not exists then this line of code return error.please provide a way so i can access client id of control.
var str = jquery("#<%=btnBook1.ClientID%>").attr("id").toString();
Please provide solution as soon as possible.
thanks in advance
推荐答案
试试这个
Try this
<%=(this.FindControl("btnBook1") == null) ? "" : this.FindControl("btnBook1").ClientID%>
你的代码很有趣,因为你试图通过已经id
> id ,即使它没有返回错误。这不是很明显吗?如果按钮不存在,你想要什么?它应该返回错误。把这一行包装在try-catch中,但最好重新考虑你的代码的一般设计...
-SA
Your code is funny, because you are trying to findid
via alreadyid
, even if it did not return error. Isn''t it obvious? If button does not exist, what do you want? It should return error. Well wrap this line in try-catch, but better rethink your general design of your code…
—SA
这篇关于如何找到控制客户端ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文