2011-02-03 118 views

回答

5

这里是链接,通过它可以很容易地从eascape按下按钮关闭该窗口:

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

希望这有助于。

+0

谢谢苏雷什,但在这里我必须在我的身体标记中添加onkeydown =“body_onkeydown()”。但我的身体标记在母版页中。那么如何在body标签中添加这个事件。 – 2011-02-03 05:23:15

3

添加脚本在你的页面关闭模式弹出了ESC键

<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

,我们有两个ModalPopupExtender控制, 首先设置每个模态控制的BehaviorID到可以从Java访问脚本, 我命名第一个控件P2和第二个P3。 下面写代码通过头标记:

<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> 

我们使用$找到(P2),以确保该模式弹出的页面中存在。