简体   繁体   中英

Close the Ajax Modal popup window on Esc keypress

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

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.

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM