Close the Ajax Modal popup window on Esc keypress

11.3k Views Asked by At

I had shown a Panel Pop up windows using Ajax and what i have to do is i want to close the window when user press the Esc key.

IS this is possible? Please help me if any one know about this or previously done this.

Thanks

3

There are 3 best solutions below

1
On BEST ANSWER

Here is the link through which you can easily close the window from eascape button press:

http://www.codeproject.com/KB/scripting/Javascript_for_modalpopup.aspx

hope this help.

0
On

Add the script in your page to close the modal pop up with the ESC key

   <script type="text/javascript">

    function pageLoad(sender, args){
        if(!args.get_isPartialLoad()){
            //  add our handler to the document's
            //  keydown event
            $addHandler(document, "keydown", onKeyDown);
        }
    }

    function onKeyDown(e){
        if(e && e.keyCode == Sys.UI.Key.esc){
            // if the key pressed is the escape key, dismiss the dialog
            $find('mdlPopupExtender').hide();
        }
    } 

    </script>
0
On

Suppose we have two ModalPopupExtender Control, First of all set BehaviorID of each modal control to can access it from java script, I name the first control P2 and second P3. Write below code in through head tag:

<script type="text/javascript">
    document.onkeyup =Esc;
    function Esc()
    {
    var KeyID =event.keyCode;
     if(KeyID==27)
     {
     if($find("p2"))
     {
       $find("p2").hide();
     }
     if($find("p3"))
        $find("p3").hide();
     }
    }
</script>

we use $find(p2) to be sure the modal popup is existed in the page.