ASP的jQuery的Click事件:按钮 [英] jQuery Click event on asp:button

查看:412
本文介绍了ASP的jQuery的Click事件:按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器端的按钮

I have a server side button as

<asp:Button ID="btnSummary" runat="server" OnClick="btnSummary_Click" Text="Next" />

我要附加的jQuery的点击使用其ID,并没有使用替代类属性的方式活动。




我试图附加click事件为:

I want to attach the jQuery Click event using its ID and NOT using the alternative class attribute way.

I tried to attach the click event as:

$("#btnSummary").click(function() 
        {
            alert("1");
        });

不过,将不会触发其Click事件。此外,我也尝试过 $(ID [$ btnSummary])



有什么办法附加ASP的单击事件:使用jQuery的一个按钮上的按钮

But, its click event is not fired. Also, I have also tried $("id[$btnSummary]").

Is there any way to attach the click event on asp:button using jQuery without the class attribute on the button?

推荐答案

你们有些人可以在这里找到的选项

Some of the options you have can be found here

<一个href=\"http://stackoverflow.com/questions/497802/how-to-stop-asp-net-from-changing-ids-in-order-to-use-jquery/498972#498972\">How从不断变化的IDS为了使用jQuery 停止ASP.NET

How to stop ASP.NET from changing ids in order to use jQuery

编辑:

其他答案阅读您的意见后,这听起来像你需要的onclick事件处理程序绑定的ASP.NET AJAX的的pageLoad ,所以它必然在每次回传,包括异步回发。在另一方面,$(文件)。就绪()在初始页面加载绑定只有一次

After reading your comments on other answers, it sounds like you need to bind the onclick event handler inside of ASP.NET AJAX's pageLoad, so that it is bound on every postback, including asynchronous postbacks. On the other hand, $(document).ready() binds only once on initial page load

function pageLoad(sender, args)
{
     $("#<%=btnSummary.ClientID %>").click(function() 
    {
        alert("1");
    });
}

戴夫·沃德写了一个好的文章之间的差异页面加载和$(文件)。就绪()

这篇关于ASP的jQuery的Click事件:按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆