将事件附加到超链接上,然后在更新面板中单击吗? [英] Attach event to hyperlink click inside update panel?

查看:69
本文介绍了将事件附加到超链接上,然后在更新面板中单击吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将单击事件(单击时显示警报)添加到文档(就绪)的UpdatePanel内的html超链接中.但是,当我单击超链接时,永远不会触发该事件.是因为ASync回传吗?正确的方法是什么?

I am adding a click event (display alert on click) to a html hyperlink inside an UpdatePanel on document(ready). However, the event never gets fired when I click the hyperlink. Is it because of ASync postback? What is the correct way to do this?

 $(document).ready(function(){
            $('#addExcl').click(function(){
                alert('asassasaas');return false;
            });    
    });

推荐答案

您需要在每个ajax更新中附加偶数,因为dom结构已更改,事件在更新过程中丢失了.

You need to attach the even in every ajax update because the dom struct is change and the events are lost on the part of the update.

var prm = Sys.WebForms.PageRequestManager.getInstance();    
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args) {      
}

function EndRequest(sender, args) {
         $('#addExcl').click(function(){
             alert('asassasaas');
             return false;
         }); 
}

这篇关于将事件附加到超链接上,然后在更新面板中单击吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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