使用jQuery.Validate(2)

using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Web;
using  System.Web.UI;
using  System.Web.UI.WebControls;

namespace  Web.Ajax.Validate
{
    
public   partial   class  AjaxLogin : System.Web.UI.Page
    {
        
protected   void  Page_Load( object  sender, EventArgs e)
        {
            
if  (Request[ " user " !=   null   &&  Request[ " password " !=   null )
            {
                
string  rtn  =   "" ;
                
if  (Request[ " user " ==   " admin "   &&  Request[ " password " ==   " admin " )
                {
                    rtn 
=   " Login success ! " ;
                }
                
else
                {
                    rtn 
=   " Your user or password is wrong (must be admin). " ;
                }
                Response.Clear();
                Response.Write(rtn);
                Response.End();
            }
        }
    }
}
<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeBehind = " AjaxLogin.aspx.cs "  Inherits = " Web.Ajax.Validate.AjaxLogin "   %>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
  
< title ></ title >
  
< style  type ="text/css" >
    body, div 
{  font-family :  'lucida grande', helvetica, verdana, arial, sans-serif  }
    .warning 
{  color :  red ;   }
    form
{ margin : 0 ; padding : 0 ; }
    fieldset 
{ padding : 8px ; width : 688px ; }     
    legend 
{ padding : 0 ; color : #000 ; }
    input, textarea, select 
{ margin : 0 ; font-size : 100% ; font-family : inherit ; width : 168px ; border : 1px solid #A3C6D4 ; }
      select 
{  padding :  0 ;   }
      form.cmxform 
{ width : 370px ; font-size : 1.0em ; color : #333 ; }
    form.cmxform label.error, label.error 
{ color :  red ; font-style :  italic }
    div.error 
{  display :  none ;   }
    input:focus 
{  border :  1px dotted black ;   }
    input.error 
{  border :  1px solid red ;   }
    form.cmxform .gray * 
{  color :  gray ;   }

  
</ style >
  
< script  src ="http://www.cnblogs.com/scripts/jquery.js"  type ="text/javascript" ></ script >
  
< script  src ="http://www.cnblogs.com/scripts/jquery.form.js"  type ="text/javascript" ></ script >
  
< script  src ="http://www.cnblogs.com/scripts/jquery.validate.js"  type ="text/javascript" ></ script >
  
< script  src ="http://www.cnblogs.com/scripts/cmxforms.js"  type ="text/javascript" ></ script >
  
< script  type ="text/javascript" >
    jQuery(
function () {
      
//  show a simple loading indicator
       var  loader  =  jQuery( ' <div id="loader"><img src="http://www.cnblogs.com/images/loading.gif" alt="loading" /></div> ' )
            .css({ position: 
" relative " , top:  " 1em " , left:  " 25em "  })
            .appendTo(
" body " )
            .hide();
      jQuery().ajaxStart(
function () {
        loader.show();
      }).ajaxStop(
function () {
        loader.hide();
      }).ajaxError(
function (a, b, e) {
        
throw  e;
      });

      
var  v  =  jQuery( " #form " ).validate({
        submitHandler: 
function (form) {
          jQuery(form).ajaxSubmit({
            target: 
" #result "
          });
        }
      });

      jQuery(
" #reset " ).click( function () {
        v.resetForm();
      });
    });
  
</ script >
</ head >
< body >
< form  method ="post"  class ="cmxform"  id ="form"  action ="ajaxlogin.aspx" >
    
< fieldset >
        
< legend > Login Form (Enter "admin" as password) </ legend >
        
< p >
            
< label  for ="user" > Username </ label >
            
< input  id ="user"  name ="user"  title ="Please enter your username (at least 3 characters)"  class ="required"  minlength ="3"   />
        
</ p >
        
< p >
            
< label  for ="pass" > Password </ label >
            
< input  type ="password"  name ="password"  id ="password"  class ="required"  minlength ="5"   />
        
</ p >
        
< p >
            
< input  class ="submit"  type ="submit"  value ="Login" />
        
</ p >
    
</ fieldset >
</ form >

< div  id ="result" > Please login! </ div >

< br />
< button  id ="reset" > Programmatically reset above form! </ button >
</ body >
</ html >

转载于:https://www.cnblogs.com/angushine/archive/2008/12/25/1362552.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值