一、JS添加代码,判断是否有OnSubmit事件
文件位置:YZSoft/Forms/src/Validator.js
//=====判断是否有OnSubmit事件===== if (typeof (OnSubmit) != 'undefined') { var func = OnSubmit; if (func(validationGroup) === false) return false; }
二、OnSubmit方法
代码位置:需要判断的表单中
<script> function OnSubmit() { var PID = $("#XTextBox2").find(".yz-xform-field-ele-input").val(); var a = true; $.ajax({ url: "../合同管理/CollectionManagement.ashx", data: { "PID": PID }, type: "post", dataType: "text", async: false, //异步:关闭(将异步变为同步) success: function (data) { if (data=="false") { alert("工程编号已存在!请重新输入!"); a = false; } } }); return a; } </script>
三、ajax一般处理程序
<%@ WebHandler Language="C#" Class="CollectionManagement" %> using System; using System.Web; using System.Linq; using System.Collections.Generic; using System.Collections; public class CollectionManagement : IHttpHandler { public void ProcessRequest (HttpContext context) { string PID=context.Request["PID"]; //PID = "GC422444"; //string json = "{"P":"F"}"; string flag = "true"; using (CollectionManagementDataClassesDataContext cm = new CollectionManagementDataClassesDataContext()) { List<EngineeringManagement> P = cm.EngineeringManagement.Where(r => r.ProjectID == PID).ToList(); if (P.Count != 0) { flag = "false"; } } context.Response.Write(flag); context.Response.End(); } public bool IsReusable { get { return false; } } }