首页 新闻 会员 周边

ValidationEngine验证问题,不能用直

0
悬赏园豆:30 [已关闭问题] 关闭于 2012-04-06 22:45

前台:

View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApp.Default" %>

<!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>
<link href="css/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
<link href="css/StyleSheet.css" rel="stylesheet" type="text/css" />
<link href="css/template.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript"></script>
<script src="js/languages/jquery.validationEngine-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#form1").validationEngine({
ajaxFormValidation: true,
promptPosition: "centerRight",
});
});
</script>
</head>
<body>
<form id="form1" class="formular" runat="server">
<fieldset>
<legend>用户注册:</legend>
<label>
<span>用户名:</span>
<asp:TextBox ID="TextBox1" runat="server" class="validate[required,minSize[5],maxSize[16]],ajax[ajaxUserCall] text-input"></asp:TextBox>
</label>
<label>
<span>密码:</span>
<asp:TextBox ID="TextBox2" TextMode="Password" runat="server" class="validate[required] text-input"></asp:TextBox>
</label>
<label>
<span>确认密码:</span>
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password" class="validate[required] text-input"></asp:TextBox>
</label>
<label>
<span>邮箱:</span>
<asp:TextBox ID="TextBox4" runat="server" class="validate[required,custom[email]] text-input"></asp:TextBox>
</label>
<input id="test_input" class="validate[required, ajax[ajaxUserCall]]" name="test" type="submit" onclick="Button1_Click" />
</fieldset>
</form>
</body>
</html>

后台:

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApp.Entity;
using System.Web.Services;

namespace WebApp
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public void Button1_Click(object sender, EventArgs e)
{
User sss = new User();
sss.UserName = TextBox1.Text.Trim();
sss.PassWord = TextBox2.Text;
sss.EMail = TextBox4.Text.Trim();
int flag = sss.Add();
if (flag > 0)
{
Response.Write("<script>alert('添加成功!')</script>");
Response.Redirect("Default.aspx");
Response.End();
}
else
{
Response.Redirect("Default.aspx");
Response.Write("<script>alert('添加失败!')</script>");
Response.End();
}
}
}
}

实体:

View Code
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using WebApp.DAL;

namespace WebApp.Entity
{
public class User
{
public string UserName { get; set; }
public string PassWord { get; set; }
public string PassWord2 { get; set; }
public string EMail { get; set; }

public int Add()
{
string sqlstr = "insert into [User](UserName,[PassWord],EMail)values(@UserName,@PassWord,@EMail)";
List<SqlParameter> param = new List<SqlParameter>();
param.Add(new SqlParameter("UserName", UserName));
param.Add(new SqlParameter("PassWord", PassWord));
param.Add(new SqlParameter("EMail", EMail));
DbHelper db = new DbHelper();
return db.ExecuteSql(sqlstr, param.ToArray());
}
}
}

异步数据处理函数

View Code
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using WebApp.DAL;

namespace WebApp
{
///<summary>
/// Handler1 的摘要说明
///</summary>
public class Handler1 : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
string str = context.Request["fieldId"].ToString();
string str1 = context.Request["fieldValue"].ToString();
DbHelper db = new DbHelper();
string sqlstr = "select UserName from [User] where UserName=@UserName";
SqlParameter[] para ={ new SqlParameter("UserName",str1)};
string str2 = db.ExecuteSqlFirst(sqlstr, para);
jsonsj temp = new jsonsj(str, str1.Equals(str2)?false:true);
context.Response.ContentType = "text/plain";
context.Response.Write(temp.ToString());
context.Response.End();
}

public bool IsReusable
{
get
{
return false;
}
}

public class jsonsj
{
private string ID;
private bool flag;
public jsonsj(string fieldId, bool aflag)
{
ID = fieldId;
flag = aflag;
}
public override string ToString()
{
StringBuilder str = new StringBuilder();
str.Append("[\"").Append(ID).Append("\",").Append(flag.ToString().ToLower()).Append("]");
return str.ToString();
}
}
}
}

点提交时,不进行表单验证,看了一个国外的说用input type="submit"能提交,确实能提交但是怎么用后台处理并返回,表单怎么验证,等待高手解答:




 

不能迷糊的主页 不能迷糊 | 初学一级 | 园豆:158
提问于:2012-03-31 23:12
< >
分享
所有回答(1)
0

<script>     
        $(document).ready(function() {   
            $("#formID").validationEngine({   
            validationEventTriggers:"blur",  //触发的事件  validationEventTriggers:"keyup blur",   
            inlineValidation: true,//是否即时验证,false为提交表单时验证,默认true   
            success :  false,//为true时即使有不符合的也提交表单,false表示只有全部通过验证了才能提交表单,默认false   
            promptPosition: "topRight",//提示所在的位置,topLeft, topRight, bottomLeft,  centerRight, bottomRight   
            //failure : function() { alert("验证失败,请检查。");  }//验证失败时调用的函数   
            //success : function() { callSuccessFunction() },//验证通过时调用的函数   
            });   
        });  
http://www.cnblogs.com/aijun/archive/2011/03/21/1989991.html

無限遐想 | 园豆:3740 (老鸟四级) | 2012-04-01 08:59

还是有点不明白,我开了ajaxFormValidation: true这个属性,做submit提交时不能页面没有跳转,也没有反映,我换了input submit进行验证时我用__doPostBack('LinkButton1', '');调用了一个隐藏的linkbutton的方法,但是提交是还是不成!

支持(0) 反对(0) 不能迷糊 | 园豆:158 (初学一级) | 2012-04-01 09:51

@第八技术:     你 必須有一個submit按鈕,還有,如果是服務器端控件,需要加上頁面 驗證屬性。

支持(0) 反对(0) 無限遐想 | 园豆:3740 (老鸟四级) | 2012-04-01 10:14

@無限遐想: 加上这个按钮了,也有返回值,页面验证属性是什么东东怎么加呀

支持(0) 反对(0) 不能迷糊 | 园豆:158 (初学一级) | 2012-04-01 14:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册