JQuery:如何从 ASP.NET 中的主页面/内容页面获取 ID 的值
我的内容页面中有这个:但如果我尝试 $("#ctl00_cphMaster_CloseButton").
,我会得到空值。
$(document).ready(function() {
$("#ctl00_cphMaster_CloseButton").click(function() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
if (r == true)
__doPostBack('CloseButton', '');
});
return false;
});
});
});
<uc1:ImageTextButton ID="CloseButton" runat="server"
ImageURL="Images/closeIcon.png"
Enabled="True" Text="Close"
CausesValidation="false" onclick="CloseButton_Click" />
更新:
我尝试过这样的操作:
$("#<%= CloseButton.ClientID %>").click(function() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
if (r == true)
__doPostBack('CloseButton', '');
});
return false;
});
});
当我运行页面时,它会抛出错误使用此代码:
$("#ctl00_cphMaster_CloseButton").click(function() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
if (r == true)
__doPostBack('CloseButton', '');
});
return false;
});
这意味着它获得了正确的 id,但为什么它会抛出一个错误,抱怨 null
Microsoft JScript 运行时错误:'null' is null or not an object
更新:
KP 建议:
$("#<%= CloseButton.ClientID %>").click(function() {
alert("yes");
});
});
i have this in my content page: but i am getting null value if i try $("#ctl00_cphMaster_CloseButton").
$(document).ready(function() {
$("#ctl00_cphMaster_CloseButton").click(function() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
if (r == true)
__doPostBack('CloseButton', '');
});
return false;
});
});
});
<uc1:ImageTextButton ID="CloseButton" runat="server"
ImageURL="Images/closeIcon.png"
Enabled="True" Text="Close"
CausesValidation="false" onclick="CloseButton_Click" />
UPDATE:
i have tried like this:
$("#<%= CloseButton.ClientID %>").click(function() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
if (r == true)
__doPostBack('CloseButton', '');
});
return false;
});
});
when i run my page it throws me an error with this code:
$("#ctl00_cphMaster_CloseButton").click(function() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
if (r == true)
__doPostBack('CloseButton', '');
});
return false;
});
it means it got the right id but why is it throwing an error complaining about null
Microsoft JScript runtime error: 'null' is null or not an object
UPDATE:
KP Suggestion:
$("#<%= CloseButton.ClientID %>").click(function() {
alert("yes");
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用 ClientID-按钮控件的属性?
Have you tried to use the ClientID-Property of the button-control?
我会选择 $("[id$=CloseButton]") 来匹配以 CloseButton 结尾的元素
I'd go with $("[id$=CloseButton]") which matches elements which end with CloseButton