如何使用javascript在updatepanel中获取回发元素?

时间:2022-03-13 03:54:51

Is there a way to find out postback element in updatepanel using javascript?

有没有办法在updatepanel中使用javascript找出回发元素?

I tried code below but args.get_postBackElement().id is undefined.

我尝试了下面的代码,但args.get_postBackElement()。id未定义。

script>
     Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

     function BeginRequestHandler(sender, args) {
        try {
            args.get_request().set_userContext(args.get_postBackElement().id);
        }
        catch (e) {
        }
    }

    function EndRequestHandler(sender, args) {
        try {
            if (args.get_error() == undefined) {
                var sName = args.get_response().get_webRequest().get_userContext();
                if (sName == "btnDetails") {
                    //DoSomething();
                }
                else {
                    //DoSomethingelse();
                }
            }
        }
        catch (e) {
        }
    }

2 个解决方案

#1


0  

Try this

<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    var postBackElementID;
    function BeginRequestHandler(sender, args) {
        try {
            postBackElementID = args.get_postBackElement().id.substring(args.get_postBackElement().id.lastIndexOf("_") + 1);
        }
        catch (e) {
        }
    }
</script> 

#2


0  

args.get_postBackElement() returns null if control is inside update panel.

如果控件在更新面板内,则args.get_postBackElement()返回null。

Try following properties to find out the element:

尝试以下属性来找出元素:

sender._postBackSettings.async - Detect whether the request is async.

sender._postBackSettings.async - 检测请求是否为异步。

sender._postBackSettings.asyncTarget - Gets the async postback control name

sender._postBackSettings.asyncTarget - 获取异步回发控件名称

$("*[name='sender._postBackSettings.asyncTarget']").attr('id') - Gets the id of the async postback control name. sender._postBackSettings.asyncTarget should be replaced by the value

$(“* [name ='sender._postBackSettings.asyncTarget']”)。attr('id') - 获取异步回发控件名称的id。 sender._postBackSettings.asyncTarget应该替换为值

#1


0  

Try this

<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    var postBackElementID;
    function BeginRequestHandler(sender, args) {
        try {
            postBackElementID = args.get_postBackElement().id.substring(args.get_postBackElement().id.lastIndexOf("_") + 1);
        }
        catch (e) {
        }
    }
</script> 

#2


0  

args.get_postBackElement() returns null if control is inside update panel.

如果控件在更新面板内,则args.get_postBackElement()返回null。

Try following properties to find out the element:

尝试以下属性来找出元素:

sender._postBackSettings.async - Detect whether the request is async.

sender._postBackSettings.async - 检测请求是否为异步。

sender._postBackSettings.asyncTarget - Gets the async postback control name

sender._postBackSettings.asyncTarget - 获取异步回发控件名称

$("*[name='sender._postBackSettings.asyncTarget']").attr('id') - Gets the id of the async postback control name. sender._postBackSettings.asyncTarget should be replaced by the value

$(“* [name ='sender._postBackSettings.asyncTarget']”)。attr('id') - 获取异步回发控件名称的id。 sender._postBackSettings.asyncTarget应该替换为值