Click here to Skip to main content
Click here to Skip to main content

Tagged as

Ajax: Identify the control that caused the Async Postback

, 12 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
There will be some scenarios where we may have to identify the sender that caused the async postback(While using update panel) . Normally we will try to identify the control by checking the sender element . This wont be always giving the correct value as multiple clicks/ elements under the...
There will be some scenarios where we may have to identify the sender that caused the async postback(While using update panel) . Normally we will try to identify the control by checking the sender element . This wont be always giving the correct value as multiple clicks/ elements under the update panel can alter this. We can identify the control that caused an async postback by sending the ID of the control along with the request as user context. You can use the following script for this.
 
<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) {
            }
        }
 
</script>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

J a a n s
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
GeneralNice one... thanks. PinmemberRavishankar Visvan27-Jul-11 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 12 Jan 2010
Article Copyright 2010 by J a a n s
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid