如何在asp.net中进行jquery验证时防止回发 [英] How to Prevent postback while jquery validation works in asp.net
本文介绍了如何在asp.net中进行jquery验证时防止回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的专家,
我正在做一个asp.net项目。我需要使用jquery验证控件...
这是我的HTML代码...
Dear Experts,
I am Doing an asp.net project. And i need to validate the controls using jquery...
Here is my HTML Code...
<form runat="server" class="input-wrapper blue-gradient glossy">
<input type="text" name="login" id="login" value="" class="input-unstyled" placeholder="Login" autocomplete="off"></li>
<input type="password" name="pass" id="pass" value="" class="input-unstyled" placeholder="Password" autocomplete="off"></li>
<button type="submit" runat="server" onclientclick="javascript:MyFunction();" onserverclick="btn_Login_Click" class="button glossy float-right" id="btn_Login">Login</button>
</form>
这是我的Javascript ...
Here is my Javascript...
function MyFunction() {
// Values
var login = $.trim($('#login').val()),
pass = $.trim($('#pass').val());
// Check inputs
if (login.length === 0) {
// Display message
alert('Please fill in your login');
return false;
}
else if (pass.length === 0) {
// Display message
alert('Please fill in your password');
return false;
}
else {
return true;
}
}
这是我的C#代码
Here is my C# Code
protected void btn_Login_Click(object sender, EventArgs e)
{
// code
}
实际上我需要验证控件首先..如果验证成功那么只会进入代码背后......
当用户文本框留空时,验证工作并且不启动回发...
PLease帮助我这样做...
谢谢和问候,
Dileep ..
Actually I need to validate the control First.. If the validation sucess then only goes to code behind ....
When a user Textbox leaves blank then the validation works and don't start the postback...
PLease Help me to do this...
Thanks and Regards,
Dileep..
推荐答案
.trim(
(' #登录跨度>)诉al()),
pass =
('#login').val()), pass =
.trim(
这篇关于如何在asp.net中进行jquery验证时防止回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文