<script type="text/javascript"> var xhr; //function createXMLHttpRequest1() { // alert(">>>"); //} function createXMLHttpRequest() { if (window.ActiveXObject) {//如果是IE浏览器 return new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) {//非IE浏览器 return new XMLHttpRequest(); } } //function createXmlHttpRequest() { // if (window.XMLHttpRequest) { // xmlHttp = new XMLHttpRequest(); // if (xmlHttp.overrideMimeType) { // xmlHttp.overrideMimeType("text/xml"); // } // } // else if (window.ActiveXObject) { // try { // xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // } // catch (e) { // xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // } // } // if (!xmlHttp) { // window.alert("你的浏览器不支持创建XMLhttpRequest对象"); // } // return xmlHttp; //} function userExists(CarNum) { if (CarNum != "") { //请求字符串 var url = "TC_Maintenance.aspx?CarNum=" + CarNum + '&_dc=' + new Date().getTime(); // 1. 创建XMLHttpRequest组件 xhr = createXMLHttpRequest(); // 2. 设置回调函数 xhr.onreadystatechange = readyDo; // 3. 初始化XMLHttpRequest组件 xhr.open("GET", url, true); // 4. 发送请求 xhr.send(null); } } function readyDo() { if (xhr.readyState == 4) { if (xhr.status == 200) { var b = xhr.responseText; if (b == "true") { document.getElementById("mess_double").style.display = "inline"; } else { document.getElementById("mess_double").style.display = "none"; } } } } </script> </head> <body> <form id="form1" runat="server" defaultbutton="btnAdd"> <asp:ScriptManager ID="smDetail" runat="server" EnablePartialRendering="true"> </asp:ScriptManager> <div class="maincontent"> <asp:UpdatePanel ID="uplDetail" runat="server"> <ContentTemplate> <div class="panel"> <div class="title">明细</div> <div class="content"> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="smartGrid2"> <tr> <th width="13%" align="left">车牌号:</th> <td width="37%"> <asp:TextBox ID="txtCarNum" runat="server" MaxLength="15" onblur="userExists(this.value) "/> <asp:RequiredFieldValidator runat="server" ID="CarNum_Null_Check" ControlToValidate="txtCarNum" ErrorMessage="“车牌号”不能为空" Display="None" Height="5px" Width="5px" /> <span class="RequiredWarningStyle" runat="server" id="spCarNum">*</span> <span id="mess_double" style="display: none; color: Red">该车牌号已存在,请重新输入</span> </td> </tr>
为问题是这样的:新建和修改在一个页面,我有一个车牌号,新建的时候判断他是否重复了?
但是问题是修改的时候也说他重复
我在list页传过来一个Id,但是怎么接收呐?var url = "TC_Maintenance.aspx?CarNum=" + CarNum + '&_dc=' + new Date().getTime();
这是在js里的
对于这种修改和新增放在一起,又要判断重复的需求。我的做法是:
不管是新增还是修改,都要提交这条记录的ID和需要判断重复的数据(新增时ID=0)。然后sql为:select count(0) from table where id <> @Id and code = @Code ,如果结果大于0,那么就是重复。
是不是修改的时候不能修改车牌,但是js里面还是去做了车牌是否重复的判断啊