[CLOSED] how to press "enter" to close X.MessageBox.Alert

  1. #1

    [CLOSED] how to press "enter" to close X.MessageBox.Alert

    when X.MessageBox.Alert("info", "error").Show() , a button on it , I want to press "enter" to close this alert window,
    how to do ? thanks.
  2. #2
    Hi @hdsoso,

    An alert box should be closed on Enter key be default. So, I am not sure that I understand the requirement.

    If you need to closed an alert box via JavaScript, please call:
    Ext.Msg.hide();
  3. #3
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login1.aspx.cs" Inherits="extdemo.pages.login1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>LOGIN</title>
        <script runat="server">
            protected void verycode()
            {
                string u = this.txtUsername.Text;
                string p = this.txtPassword.Text;
                if (u == "admin" && p == "admin")
                {
                    Window1.Hide();
                  //  Session["user"] = "admin";
                    X.MessageBox.Alert("info", "success").Show();
                }
                else
                {
                    X.MessageBox.Alert("info", "failure").Show();
                }
            }
            protected void btnLogin_Click(object sender, DirectEventArgs e)
            {
                verycode();
            }
        </script>
        <script>
            Ext.getDoc().on('keydown', function (e) {
                if (e.getKey() == e.ENTER) {
                    App.btnLogin.fireEvent("click", btnLogin);
                }
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
         <ext:ResourceManager ID="ResourceManager1" runat="server" >
          </ext:ResourceManager>
            <ext:Window 
                ID="Window1" 
                runat="server" 
                Closable="false"
                Resizable="false"
                Height="150" 
                Icon="Lock" 
                Title="user login"
                Draggable="false"
                Width="350"
                Modal="true"
                BodyPadding="5"
                Layout="FormLayout">
                <Items>
                    <ext:TextField 
                        ID="txtUsername" 
                        runat="server"                     
                        FieldLabel="username" 
                        AllowBlank="false"
                        BlankText="please input username" FocusOnToFront="true"
                          />
                    <ext:TextField 
                        ID="txtPassword" 
                        runat="server" 
                        InputType="Password" 
                        FieldLabel="password" 
                        AllowBlank="false" 
                        BlankText="please input password"
                          />
                </Items>
                <Buttons>
                    <ext:Button ID="btnLogin" runat="server" Text="login" Icon="Accept">
                        <DirectEvents>
                            <Click OnEvent="btnLogin_Click">
                                <EventMask ShowMask="true" Msg="login..." MinDelay="1000" />
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                     
                </Buttons>
            </ext:Window>
        </form>
    </body>
    </html>
    here is my code , when I input wrong username and password , then pop ALERT window then i press "enter" key , i just want to close the alert window, but now it can show "login ..." again
  4. #4
    Well, it is fired because of:
    Ext.getDoc().on('keydown', function (e) {
        if (e.getKey() == e.ENTER) {
            App.btnLogin.fireEvent("click", btnLogin);
        }
    });
    I think you can replace it with this setting for the Window.
    DefaultButton="btnLogin"
  5. #5
    thanks.you can close the post.

Similar Threads

  1. [CLOSED] press the ENTER key
    By majunior in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Nov 15, 2012, 10:13 PM
  2. Need Help : MessageBox setIcon() not working on Alert()
    By santhu12smart in forum 1.x Help
    Replies: 6
    Last Post: Dec 09, 2011, 12:10 PM
  3. Press Enter key should work on search button
    By Nagaraju in forum 1.x Help
    Replies: 1
    Last Post: Oct 09, 2011, 5:09 PM
  4. How do press Enter key jump like Tab?
    By whs2893 in forum 1.x Help
    Replies: 6
    Last Post: Mar 23, 2011, 3:07 AM
  5. Replies: 0
    Last Post: Sep 10, 2009, 8:59 AM

Posting Permissions