0

我有几个需要字段验证的文本框。在同一页面中,有一个后退按钮和下一个按钮。当我单击后退按钮时,验证正在工作,当我单击下一个按钮时,验证不起作用(意味着表单正在移动到下一页)

请帮我纠正

              <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="RequestorForm.aspx.vb"

                  Inherits="WebApplication1.RequestorForm" %>



              <!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 id="Head1" runat="server">

                  <title>Requestor Form</title>

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

                  <script language="javascript" type="text/javascript">

                      //Call Server Event on User id onblur()
                      function CallClientEvent() {
                          __doPostBack("txt_view1_userID_TextChanged", "");
                      }

                      function CheckValidation() {



                          Page_ClientValidate();

                          if (Page_IsValid) {

                              if (CheckRoleValidation()) {

                                  if ('<%=strRoleType%>' == 'chkBx_Store_wu') {

                                      return CheckTeamViewerDep();

                                  }

                              }

                              else {

                                  return false;

                              }

                          }

                      }



                      function CheckTeamViewerDep() {



                          var ctl = document.getElementById('chkbx_teamLeadStockRoom');

                          if (ctl.disabled) {

                              return true;

                          }



                          var tDiv = document.getElementById('chkDepGroup');

                          var chkitm = tDiv.getElementsByTagName("input");

                          for (var i = 0; i < chkitm.length; i++) {

                              if (chkitm[i].checked) {

                                  return true;

                              }

                          }

                          var ctlvalidate = document.getElementById('span_chkDepGroup');

                          ctlvalidate.innerHTML = 'Please select Dep';

                          return false;



                      }

                      function CheckRoleValidation() {

                          //var cblItm = '<%=gvRoleDep%>';

                          var tDiv = document.getElementById('gvRoleDep');

                          var chkitm = tDiv.getElementsByTagName("input");

                          var flag = false;

                          var chkItemCount = 0;

                          for (var i = 0; i < chkitm.length; i++) {

                              if (chkitm[i].checked) {

                                  chkItemCount++;

                                  flag = true;

                              }

                          }

                          var ctlvalidate = document.getElementById('lbl_chkBx_store_wu');

                          if (!flag) {

                              ctlvalidate.innerHTML = 'Please select Role(s)';

                              return false;

                          }

                          if (chkItemCount > 5) {

                              ctlvalidate.innerHTML = 'Maximum of 5 Role(s) only can be checked';

                              return false;

                          }

                      }

                      function ValidateDropDown() {

                          Page_ClientValidate();
                          flag = 1;

                          objTOR = document.getElementById('ddl_view0_typeOfRequest');

                          objWUL = document.getElementById('ddl_view0_wuLevel');

                          if (Page_IsValid) {

                              //alert(objTOR.selectedIndex);

                              TOR = document.getElementById('span_ddl_view0_typeOfRequest');

                              WUL = document.getElementById('span_ddl_view0_wuLevel');

                              if (objTOR.selectedIndex == 0) {

                                  //alert('Select a value:');

                                  TOR.innerHTML = "*Please select a Type of Request";

                                  flag = 0;

                              }

                              else

                                  TOR.innerHTML = " ";

              //                if (objWUL.selectedIndex == 0) {

              //                    WUL.innerHTML = "*Please select a W A";

              //                    flag = 0;

              //                }

              //                else

              //                    WUL.innerHTML = " ";



                              if (flag == 0)

                                  return false;

                              return true;



                          }



                      }

                  </script>    

              </head>

              <body>

                  <form id="form1" runat="server">

                  <div style="margin-left: 10px">

                      <asp:MultiView runat="server" ID="mvRequestorForm" ActiveViewIndex="0">

                          <asp:View runat="server" ID="view_0">

                              <h1 class="blue">
                                  <asp:Label ID="lbl_viewTitle0" runat="server" Text="Label"></asp:Label>
                              </h1>
                              <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                  <tr>
                                      <td class="tabRow" width="150">
                                          <asp:Label ID="lbl_view0_firstName" runat="server" Text="Firstname "></asp:Label>
                                      </td>
                                      <td width="200">
                                          <asp:TextBox ID="txt_firstName" runat="server" AutoCompleteType="FirstName" 
                                              CssClass="text_box_3" TabIndex="1"></asp:TextBox>
                                          &nbsp;<asp:Label ID="Label5" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                      </td>
                                      <td>
                                          <asp:RequiredFieldValidator ID="Validator_FirstName" runat="server" 
                                              ControlToValidate="txt_firstName" ErrorMessage="* Required field" 
                                              ValidationGroup="Form1"></asp:RequiredFieldValidator>
                                      </td>

                                  </tr>
                                  <tr>
                                      <td class="tabRow">
                                          <asp:Label ID="lbl_view0_surname" runat="server" Text="Surname"></asp:Label>
                                      </td>
                                      <td>
                                          <asp:TextBox ID="txtSurName" runat="server" AutoCompleteType="LastName" 
                                              CssClass="text_box_3" TabIndex="3"></asp:TextBox>
                                          &nbsp;<asp:Label ID="Label6" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                      </td>
                                      <td>
                                          <asp:RequiredFieldValidator ID="Validator_Surname" runat="server" 
                                              ControlToValidate="txtSurName" ErrorMessage="* Required field" 
                                              ValidationGroup="Form1"></asp:RequiredFieldValidator>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td class="tabRow">
                                          <asp:Label ID="lbl_view0_ContactNum" runat="server" Text="Contact number"></asp:Label>
                                      </td>
                                      <td>
                                          <asp:TextBox ID="txt_contactNum" runat="server" 
                                              AutoCompleteType="BusinessPhone" CssClass="text_box_3" TabIndex="3"></asp:TextBox>
                                          &nbsp;<asp:Label ID="Label7" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                      </td>
                                      <td>
                                          <asp:RequiredFieldValidator ID="Validator_ContactNumber" runat="server" 
                                              ControlToValidate="txt_contactNum" ErrorMessage="* Required field" 
                                              ValidationGroup="Form1"></asp:RequiredFieldValidator>
                                          <asp:RangeValidator ID="RangeValidator1" runat="server" 
                                              ControlToValidate="txt_contactNum" ErrorMessage="Enter a numeric value" 
                                              MaximumValue="99999999999999" MinimumValue="0"></asp:RangeValidator>    
                                      </td>
                                  </tr>
                              </table>
                              <hr class="blue" />
                              <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                  <tr>
                                      <td class="tabRow" width="150">
                                          <asp:Label ID="lbl_view0_typeOfRequest" runat="server" Text="Type of request"></asp:Label>
                                      </td>
                                      <td width="500">
                                          <asp:DropDownList ID="ddl_view0_typeOfRequest" runat="server" 
                                              CssClass="drop_down_t" TabIndex="4">
                                              <asp:ListItem Value="-1">Please select...</asp:ListItem>
                                              <asp:ListItem>New</asp:ListItem>
                                              <asp:ListItem>Update</asp:ListItem>
                                              <asp:ListItem>Delete</asp:ListItem>
                                          </asp:DropDownList>
                                          <span ID="span_ddl_view0_typeOfRequest" class="errorText"></span>
                                      </td>
                                      <td>
                                          &nbsp;
                                      </td>
                                  </tr>
                                  <tr>
                                      <td class="tabRow">
                                          <asp:Label ID="lbl_view0_wuLevel" runat="server" Text="W A"></asp:Label>
                                      </td>
                                      <td>
                                          <asp:DropDownList ID="ddl_view0_wuLevel" runat="server" 
                                              CssClass="drop_down_t" TabIndex="5">
                                              <asp:ListItem Selected="True" Value="3">Store</asp:ListItem>
                                          </asp:DropDownList>
                                          <span ID="span_ddl_view0_wuLevel" class="errorText">
                                          </span>
                                      </td>
                                      <td>
                                          &nbsp;
                                      </td>
                                  </tr>

                                  <tr> <td>&nbsp;</td> <td></td><td>&nbsp;</td></tr>

                              </table>
                              <asp:Label ID="lblCaption1" runat="server" 
                                          Text="*  Represents fields that needs to be filled mandatory" 
                                          Font-Size="XX-Small" ForeColor="#FF3300"></asp:Label> 
                              <br />
                              <hr />
                              <asp:Button ID="btn_View0_Next" runat="server" 
                                  OnClientClick="return ValidateDropDown();" Text="Next" 
                                  ValidationGroup="Form1" />
                              <br />

                          </asp:View>

                          <asp:View runat="server" ID="view_1">

                              <asp:ScriptManager ID="scrMgr" runat="server">

                              </asp:ScriptManager>
                              <table>
                                  <tr>
                                      <td><asp:Label ID="lblException" CssClass="errorText" runat="server"></asp:Label></td>
                                  </tr>
                              </table>
                              <h1 class="blue">

                                  <asp:Label ID="lbl_viewTitle1" runat="server" Text="Label"></asp:Label>

                              </h1>

                              <table border="0">

                                  <tr>

                                      <td>

                                          <table border="1" style="border-color:Green; border-width:thin;" width="100%">

                                              <tr>

                                                  <td valign="top">

                                                      <table border="0" cellpadding="0" cellspacing="0" width="100%">

                                                          <tr id="trUserDetail" runat="server">

                                                              <td class="tabRow">

                                                                  <asp:Label ID="lbl_view1_userID" runat="server" 

                                                                  Text="User ID "></asp:Label>

                                                              </td>

                                                              <td>

                                                                  <asp:TextBox ID="txt_view1_userID" runat="server" Text="" onblur="CallClientEvent()"  AutoPostBack="true" >

                                                                  </asp:TextBox>
                                                                  &nbsp;<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="*"></asp:Label>
                                                                  &nbsp;<div class="smallText" nowrap>&nbsp;&nbsp; (This would be the ID you                                would normally log on with.)</div>

                                                              </td>

                                                              <td>

                                                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 

                                                                      ControlToValidate="txt_view1_userID" ErrorMessage="* Required field" 

                                                                      ValidationGroup="Form2"></asp:RequiredFieldValidator>

                                                              </td>

                                                          </tr>

                                                          <tr>

                                                      <td width="150" class="tabRow">

                                                          <asp:Label ID="lbl_panview3_label2" runat="server" Text="St Nu "></asp:Label>

                                                      </td>

                                                      <td width="200">

                                                          <asp:TextBox ID="txt_panview3_input2"  runat="server" MaxLength="4">0000</asp:TextBox>

                                                          &nbsp;<asp:Label ID="Label8" runat="server" ForeColor="Red" Text="*"></asp:Label>

                                                      </td>

                                                      <td>

                                                          <asp:RangeValidator ID="RangeValidator2" runat="server" 

                                                              ControlToValidate="txt_panview3_input2" 

                                                              ErrorMessage="Please enter a valid 4-digit St Nu " MaximumValue="999999" 

                                                              MinimumValue="1" Type="Integer" ValidationGroup="Form2"></asp:RangeValidator>

                                                      </td>

                                                  </tr>

                                                          <tr>

                                                      <td colspan="3">

                                                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                                          <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 

                                                              ControlToValidate="txt_panview3_input2" ErrorMessage="* Required field" 

                                                              ValidationGroup="Form2"></asp:RequiredFieldValidator>

                                                          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;



                                                          </td>

                                                  </tr>
                                                          <tr>

                                                              <td class="tabRow">

                                                                  <asp:Label ID="lblEmployeeNumber" runat="server" 

                                                                  Text="Employee Number "></asp:Label>

                                                              </td>

                                                              <td>

                                                                  <asp:TextBox ID="txtEmployeeNumber" runat="server">

                                                                  </asp:TextBox>

                                                              </td>
                                                              <td>

                                                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 

                                                                      ControlToValidate="txtEmployeeNumber" ErrorMessage="* Required field" 

                                                                      ValidationGroup="Form2"></asp:RequiredFieldValidator>

                                                              </td>

                                                          </tr>

                                                          <tr>

                                                              <td width="150" class="tabRow">

                                                                  <asp:Label ID="lbl_view1_firstName" runat="server" Text="Firstname "></asp:Label>

                                                              </td>

                                                              <td width="200">

                                                                  <asp:TextBox ID="txt_view1_firstname" runat="server"></asp:TextBox>

                                                                  &nbsp;<asp:Label ID="Label9" runat="server" ForeColor="Red" Text="*"></asp:Label>

                                                              </td>

                                                              <td>

                                                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 

                                                                      ControlToValidate="txt_view1_firstname" ErrorMessage="* Required field" 

                                                                      ValidationGroup="Form2"></asp:RequiredFieldValidator>

                                                              </td>

                                                          </tr>

                                                          <tr>

                                                              <td class="tabRow">

                                                                  <asp:Label ID="lbl_view1_surname" runat="server" Text="Surname "></asp:Label>

                                                              </td>

                                                              <td>

                                                                  <asp:TextBox ID="txt_view1_surname" runat="server"></asp:TextBox>

                                                                  &nbsp;<asp:Label ID="Label10" runat="server" ForeColor="Red" Text="*"></asp:Label>

                                                              </td>

                                                              <td>

                                                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 

                                                                      ControlToValidate="txt_view1_surname" ErrorMessage="* Required field" 

                                                                      ValidationGroup="Form2"></asp:RequiredFieldValidator>

                                                              </td>

                                                          </tr>



                                                      </table>
              <asp:Label ID="lblCaption2" runat="server" 
                                          Text="*  Represents fields that needs to be filled mandatory" 
                                          Font-Size="XX-Small" ForeColor="Red"></asp:Label> 
                                                      <hr />

                              <table border="0" cellpadding="0" cellspacing="0" width="100%">

                                  <tr>

                                      <td>

                                          <asp:Panel ID="panelHO" runat="server">

                                              <table border="0" cellpadding="0" cellspacing="0" width="100%">

                                                  <tr>

                                                      <td align="left" width="200">

                                                          <asp:Label ID="lbl_HO_wu" runat="server" CssClass="boldLabel" 

                                                              Text="Role" />

                                                      </td>

                                                      <td align="left" width="200">

                                                          <asp:Label ID="lbl_panview1_label1" runat="server" CssClass="boldLabel" 

                                                              Text="Dep" />

                                                      </td>

                                                      <td>

                                                          &nbsp;

                                                      </td>

                                                  </tr>

                                                  <tr>

                                                      <td colspan="3">

                                                          &nbsp;

                                                      </td>

                                                  </tr>

                                                  <tr>

                                                      <td align="left" valign="top">

                                                          <asp:CheckBoxList ID="chkBx_HO_wu" runat="server" />

                                                          <span id="lbl_chkBx_HO_wu" class="errorText"></span>

                                                      </td>

                                                      <td align="left" valign="top">

                                                          <asp:DropDownList ID="ddl_panview1_ddinput1" runat="server">

                                                              <asp:ListItem>Avebury</asp:ListItem>

                                                          </asp:DropDownList>

                                                      </td>

                                                      <td>

                                                          &nbsp;

                                                      </td>

                                                  </tr>

                                              </table>

                                          </asp:Panel>

                                          <asp:Panel ID="panelRegion" runat="server">

                                              <table border="0" cellpadding="0" cellspacing="0" width="100%">

                                                  <tr>

                                                      <td width="30%">

                                                          <asp:Label ID="lbl_Region_wu" runat="server" CssClass="boldLabel" 

                                                              Text="Role" />

                                                      </td>

                                                      <td width="30%">

                                                          <asp:Label ID="lbl_panview2_label1" runat="server" CssClass="boldLabel" 

                                                              Text="Region" />

                                                      </td>

                                                      <td>

                                                          &nbsp;</td>

                                                  </tr>

                                                  <tr>

                                                      <td colspan="3">

                                                          &nbsp;

                                                      </td>

                                                  </tr>

                                                  <tr>

                                                      <td valign="top">

                                                          <asp:CheckBoxList ID="chkBx_Region_wu" runat="server" />

                                                          <span id="lbl_chkBx_Region_wu" class="errorText"></span>



                                                      </td>

                                                      <td valign="top">

                                                          <asp:DropDownList ID="ddl_panview2_ddinput1" runat="server">

                                                              <asp:ListItem>Northern (NORTHERN)</asp:ListItem>

                                                              <asp:ListItem>Central (CENTRAL)</asp:ListItem>

                                                              <asp:ListItem>Southern (SOUTHERN)</asp:ListItem>
4

2 回答 2

2

两种可能性立即浮现在脑海:

  1. “下一步”按钮的CausesValidation属性设置为false
  2. “下一步”按钮ValidationGroup与其他控件不同。
于 2009-09-16T13:47:55.987 回答
1

确保在您希望在单击时进行验证的按钮上的 CausesValidation 属性设置为 true。

<asp:Button CausesValidation="TRUE" runat="server" />
于 2009-09-16T13:45:36.523 回答