当页面中(比如弹出框SelectPage)没有textbox等控件如何按Esc关闭

时间:2022-02-01 09:24:30

1.在网页上添加一个空白的ASPxTextBox控件

<dxe:ASPxTextBox ID="txt_Name" Width="1" runat="server" ReadOnly="true" Border-BorderStyle="None">
                    </dxe:ASPxTextBox>

2.设置焦点在PageInit事件加入

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txt_Name.Focus();
        }
    }

3.在aspx页面加入一段Script:
    <script type="text/javascript">
        function $(s) {
            return document.getElementById(s) ? document.getElementById(s) : s;
        }
        function keydown(e) {
            if (e.keyCode == 27) { parent.ClosePopupCtr(); }
        }
        document.onkeydown = keydown;
    </script>

4.在父页面添加函数:

function ClosePopupCtr() {
    popubCtr.Hide();
    popubCtr.SetContentUrl('about:blank');
}