在Asp.Net项目中应用Jquery.validation时遇到的一个问题

本文介绍了一个ASP.NET项目中使用jQuery Validation插件导致按钮事件无法触发的问题,并提供了具体的解决方案。

近在处理的一个asp.net项目中应用了jquery.validation来进行客户端的验证,感觉挺好的。不过在使用中遇到了一个问题,就是在应用了jquery.validation后导致asp.net的按钮无法触发事件,页面代码如下:

<%
@ 
Page 
Language
="C#" 
AutoEventWireup
="true" 
CodeFile
="ChangePassword.aspx.cs" 
Inherits
="Individuation_ChangePassword" 
%>

<! 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 runat ="server">
<
title > 密码修改</ title >

<
script type ="text/javascript" src ="../JS/jquery.js"></ script >

<
script type ="text/javascript" src ="../JS/jquery.validate.pack.js"></ script >

<
script type ="text/javascript" src ="../JS/cmxforms.js"></ script >

<
link href ="../CSS/screen.css" rel ="stylesheet" type ="text/css" />


<
script type ="text/javascript">
$.validator.setDefaults({
submitHandler: function (form) { form.submit(); }
});

$().ready(function () {

// validate signup form on keyup and submit
$("#form1" ).validate({
rules: {
txtOldPassword: "required" ,
txtNewPassword: "required" ,
txtConfirmPassword: "required" ,
txtOldPassword: {
required: true
},
txtNewPassword: {
required: true ,
minlength: 3
},
txtConfirmPassword: {
required: true ,
minlength: 3,
equalTo: "#txtNewPassword"
}
},
messages: {
txtOldPassword: {
required: "请输入原密码!"
},
txtNewPassword: {
required: "请输入新密码!" ,
minlength: "新密码长度不能小于为3位!"
},
txtConfirmPassword: {
required: "请确认新密码!" ,
minlength: "新密码长度不能小于为3位!" ,
equalTo: "两次输入的密码不一致!"
}

}
});
});
</ script >
<
style type ="text/css">


</
style >

</
head >
<
body >

<
div id ="main">
<
form class ="cmxform" id ="form1" runat ="server" >
<
fieldset >
<
legend > 密码修改</ legend >

<
p >
<
label for ="txtOldPassword"> 原密码</ label >
<
asp : TextBox ID ="txtOldPassword" runat ="server" MaxLength ="15" TextMode ="Password"></ asp : TextBox >
</
p >
<
p >
<
label for ="txtNewPassword"> 输入新密码</ label >
<
asp : TextBox ID ="txtNewPassword" runat ="server" MaxLength ="15" TextMode ="Password" ></ asp : TextBox >
</
p >
<
p >
<
label for ="txtConfirmPassword"> 确认新密码</ label >
<
asp : TextBox ID ="txtConfirmPassword" runat ="server" MaxLength ="15" TextMode ="Password" ></ asp : TextBox >
</
p >
<
p >
<
asp : Button ID ="btnSubmit" class ="btn3_mouseout" onmouseover ="this.className='btn3_mouseover'"
onmouseout ="this.className='btn3_mouseout'" onmousedown ="this.className='btn3_mousedown'"
onmouseup ="this.className='btn3_mouseup'" title ="提交" runat ="server"
Text ="提交" onclick ="btnSubmit_Click" />

<
input type ="button" id ="btnCancel" value ="取消" class ="btn3_mouseout" onmouseover ="this.className='btn3_mouseover'"
onmouseout ="this.className='btn3_mouseout'" onmousedown ="this.className='btn3_mousedown'"
onmouseup ="this.className='btn3_mouseup'" />


</ p >
</
fieldset >
</
form >
</
div >
</
body >
</
html >


经过分析得出原因:
经过一番折腾后,通过在页面上加入了下面的一行代码,解决问题,但对原理还不是太清楚I dont know

<
input 
type
="hidden" 
name
="btnSubmit" 
value
=" 确定 " />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值