//updated to show proper method si...">

Check which control triggered the AJAX request

asp.net 2.0 / jQuery / AJAX

<script type="text/javascript">
//updated to show proper method signature

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(hideMessage);

function hideMessage(sender, args)
{
    var ctl = args.get_postBackElement();
    //check if ctl is the disired control
    //hide user notification message
}
</script>

I have several controls on the page that can trigger an AJAX request, but I want my js to fire when I click one specific button. how can I check which control triggered the request, so I can start JS accordingly.

EDIT: I worked on this, but I still would like to know if I can do it this way.

: JS onclick, UpdatePanel, , JS , AJAX- , . myLabel.Text , js , $(myLabel.CliendID) innerHTML js. innerHTML - , , "" AJAX. , .

edit2: , "",

.

+3
3

, , , . javascript-.

function pageLoad() {
    if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequest);
    }
}
function endRequestHandler(sender, args) {
    if (sender._postBackSettings.sourceElement.id == '<%= gvResults.ClientID %>')        {
        //do something because of this...
    }
}
function initializeRequest(sender, args) {
    if (CheckForSessionTimeout()) {
        args.set_cancel(true);
    }
    else {
        if (sender._postBackSettings.sourceElement.id == '<%= gvResults.ClientID %>') {
             //do something because of this
        }
    }
}


.

var sessionTimeoutDateTime = new Date();
    var sessionTimeoutInterval = <%= this.SesstionTimeoutMinutes %>;

    function CheckForSessionTimeout() {
        var currentDateTime = new Date()
        var iMiliSeconds = (currentDateTime - sessionTimeoutDateTime);
        if (iMiliSeconds >= sessionTimeoutInterval) {
            ShowSessionTimeout();
            return true;
        }
        return false;
    }
+6

, javascript. , , , , .

ajax js, .

, , .

0

I read some documentation , and it turns out you can check the "sender" control. JS in question is updated to show the corresponding method signature.

This article provides an even better explanation.

0
source

Source: https://habr.com/ru/post/1703980/


All Articles