EXTJS学习系列提高篇:第四篇(转载)作者殷良胜,登陆示例
图片示例


 Code
Code //前台显示部分
//前台显示部分
 <form id="form1" runat="server">
<form id="form1" runat="server"> <div><div id="btnShow" style=" text-align:center; padding-top:300px; vertical-align:middle;"></div>
    <div><div id="btnShow" style=" text-align:center; padding-top:300px; vertical-align:middle;"></div> <script type="text/javascript">
    <script type="text/javascript"> function LoginDemo()
    function LoginDemo()
 
     {
{         //登陆窗体
        //登陆窗体 var loginPanel = new Ext.form.FormPanel
        var loginPanel = new Ext.form.FormPanel
 (
        ( {
{ id:"loginPanel",labelPad:0,labelWidth:40,frame:true,
             id:"loginPanel",labelPad:0,labelWidth:40,frame:true, items:
             items: [
             [
 
                  {xtype:"field",id:"UserName",fieldLabel:"用户名"},
{xtype:"field",id:"UserName",fieldLabel:"用户名"},
 
                  {xtype:"field",id:"Password",fieldLabel:"密   码"}
{xtype:"field",id:"Password",fieldLabel:"密   码"} ]
             ]          });
        }); var loginWindow;
        var loginWindow; if(!loginWindow)
        if(!loginWindow)
 
         {
{ loginWindow = new Ext.Window
            loginWindow = new Ext.Window
 (
            ( {
{ id:"loginWindow",
                 id:"loginWindow", title:"登陆窗口",
                 title:"登陆窗口", width:200,
                 width:200, height:127,
                 height:127,  resizable:false,
                 resizable:false,  closable:false,
                 closable:false, items:
                 items: [
                 [ loginPanel
                    loginPanel ],
                 ], buttons:
                 buttons: [
                 [
 
                      {xtype:"button",text:"确定",handler:validatorData},
{xtype:"button",text:"确定",handler:validatorData},
 
                      {xtype:"button",text:"取消",handler:function()
{xtype:"button",text:"取消",handler:function() {loginWindow.hide();}}
{loginWindow.hide();}} ]
                 ] });
            }); }
        } loginWindow.show();
        loginWindow.show();
 document.body.onkeydown = function()
        document.body.onkeydown = function() {loginWindow.show();};
{loginWindow.show();}; //连接数据库
        //连接数据库 function validatorData()
        function validatorData()
 
         {
{ var UserName = Ext.getCmp("UserName").getValue();
            var UserName = Ext.getCmp("UserName").getValue(); var Password = Ext.getCmp("Password").getValue();
            var Password = Ext.getCmp("Password").getValue(); if(Ext.util.Format.trim(UserName)==""||Ext.util.Format.trim(Password)=="")
            if(Ext.util.Format.trim(UserName)==""||Ext.util.Format.trim(Password)=="")
 
             {
{ Ext.Msg.alert("警告","请正确输入数据,用户名和密码都不能够为空!");
                Ext.Msg.alert("警告","请正确输入数据,用户名和密码都不能够为空!"); return;
                return; }
            } Ext.Ajax.request
            Ext.Ajax.request
 (
            ( {
{ http://www.cnblogs.com/mogen_yin/admin/%22ValidatorData.aspx%22,//请求的地址
                 http://www.cnblogs.com/mogen_yin/admin/%22ValidatorData.aspx%22,//请求的地址
 params:
                 params: {ParamValue:"1",ParamUserName:UserName,ParamPassword:Password},//发送的参数
{ParamValue:"1",ParamUserName:UserName,ParamPassword:Password},//发送的参数 success:function(response,option)
                 success:function(response,option)
 
                  {
{ var obj = Ext.util.JSON.decode(response.responseText);//返回的信息
                     var obj = Ext.util.JSON.decode(response.responseText);//返回的信息 if(obj.success==true)
                     if(obj.success==true)
 
                      {
{ Ext.Msg.alert("好消息","好消息:你登陆成功了!");
                         Ext.Msg.alert("好消息","好消息:你登陆成功了!"); //清除输入框
                         //清除输入框 Ext.getCmp("UserName").setValue("");
                         Ext.getCmp("UserName").setValue(""); Ext.getCmp("Password").setValue("");
                         Ext.getCmp("Password").setValue(""); loginWindow.hide();
                         loginWindow.hide(); }
                     } else
                     else
 
                      {
{ Ext.Msg.alert("坏消息","坏消息:你登陆失败了!");
                         Ext.Msg.alert("坏消息","坏消息:你登陆失败了!"); }
                     } },
                 }, failure:function()
                 failure:function()
 
                  {
{ Ext.Msg.alert("坏消息","坏消息:你登陆出现异常了!");
                     Ext.Msg.alert("坏消息","坏消息:你登陆出现异常了!"); }
                 } });
            }); }
        } //显示登陆窗口
        //显示登陆窗口 var btnShow = new Ext.Button
        var btnShow = new Ext.Button
 (
        ( {
{
 renderTo:"btnShow",text:"显示登陆窗口",handler:function()
             renderTo:"btnShow",text:"显示登陆窗口",handler:function() {loginWindow.show();}
{loginWindow.show();} });
        }); }
    } Ext.onReady(LoginDemo);
    Ext.onReady(LoginDemo);    
 </script>
</script> </div>
    </div> </form>
    </form>
 //后台代码部分
//后台代码部分
 protected void Page_Load(object sender, EventArgs e)
protected void Page_Load(object sender, EventArgs e)
 
     {
{ string ParamValue = Request["ParamValue"];
        string ParamValue = Request["ParamValue"]; if (ParamValue == "1")
        if (ParamValue == "1")
 
         {
{ string UserName = Request.QueryString["ParamUserName"];
            string UserName = Request.QueryString["ParamUserName"]; string Password = Request.QueryString["ParamPassword"];
            string Password = Request.QueryString["ParamPassword"]; //连接数据库
            //连接数据库
 连接数据库#region 连接数据库
            连接数据库#region 连接数据库 
 /**//*
            /**//* SqlConnection conn = new SqlConnection();
            SqlConnection conn = new SqlConnection(); conn.ConnectionString = "连接字符串";
            conn.ConnectionString = "连接字符串"; if (conn.State == ConnectionState.Closed)
            if (conn.State == ConnectionState.Closed) conn.Open();
                conn.Open(); SqlCommand cmd = new SqlCommand();
            SqlCommand cmd = new SqlCommand(); cmd.Connection = conn;
            cmd.Connection = conn; cmd.CommandText = string.Format(" select UserID from 表 where UserName = '{0}' and Password = '{1}'", UserName, Password);
            cmd.CommandText = string.Format(" select UserID from 表 where UserName = '{0}' and Password = '{1}'", UserName, Password); object obj = cmd.ExecuteScalar();
            object obj = cmd.ExecuteScalar(); if (obj != null)
            if (obj != null) {
            { if (Convert.ToString(obj) != "")
                if (Convert.ToString(obj) != "") {
                { Response.Write("{success:true}");
                    Response.Write("{success:true}"); }
                } else
                else {
                { Response.Write("{success:false}");
                    Response.Write("{success:false}"); }
                } }
            } else
            else {
            { Response.Write("{success:false}");
                Response.Write("{success:false}"); }
            } */
            */ #endregion
            #endregion  Response.Write("{success:true}");
            Response.Write("{success:true}"); }
        } }
    }

 
                    
                     
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号