Close the Ajax Modal popup window on Esc keypress

点点圈 提交于 2019-12-10 19:27:54

问题


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


回答1:


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.




回答2:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/4882738/close-the-ajax-modal-popup-window-on-esc-keypress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!