2016-01-25 31 views
2

工作這是我的代碼必填字段驗證不使用AjaxControlToolkit

<div> 
     <asp:ScriptManager runat="server" /> 
     <table> 
      <tr> 
       <td>Employee ID 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtEmployeeID" runat="server" /> 
        <asp:RequiredFieldValidator ErrorMessage="!" SetFocusOnError="true" EnableClientScript="true" ControlToValidate="txtEmployeeID" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>Name of the Company Placed 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtNameoftheCompanyPlaced" runat="server" /> 
        <asp:RequiredFieldValidator ErrorMessage="!" SetFocusOnError="true" EnableClientScript="true" ControlToValidate="txtNameoftheCompanyPlaced" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>Third Party Name 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtThirdPartyName" runat="server" /> 
        <asp:RequiredFieldValidator ErrorMessage="!" SetFocusOnError="true" EnableClientScript="true" ControlToValidate="txtThirdPartyName" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>Third Party Email ID 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtThirdPartyEmailID" runat="server" /> 
        <asp:RequiredFieldValidator ErrorMessage="!" SetFocusOnError="true" EnableClientScript="true" ControlToValidate="txtThirdPartyEmailID" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>Third Party Mobile No 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtThirdPartyMobileNo" runat="server" /> 
        <asp:RequiredFieldValidator ErrorMessage="!" SetFocusOnError="true" EnableClientScript="true" ControlToValidate="txtThirdPartyMobileNo" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>Third Party Mail Received Date 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtThirdPartyMailReceivedDate" runat="server" /> 
        <ajax:CalendarExtender ID="ajaxThirdPartyMailReceivedDate" TargetControlID="txtThirdPartyMailReceivedDate" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>Third Party Mail Reverted Date 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtThirdPartyMailRevertedDate" runat="server" /> 
        <ajax:CalendarExtender ID="ajaxtThirdPartyMailRevertedDate" TargetControlID="txtThirdPartyMailRevertedDate" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>No. of Times Verification Done Count 1 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtNoOfTimesVerificationDoneCount1" runat="server" /> 
       </td> 
       <td>Count 1 Date 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtCount1Date" runat="server" /> 
        <ajax:CalendarExtender ID="ajaxCount1Date" TargetControlID="txtCount1Date" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>No. of Times Verification Done Count 2 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="NoOfTimesVerificationDoneCount2" runat="server" /> 
       </td> 
       <td>Count 2 Date 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtCount2Date" runat="server" /> 
        <ajax:CalendarExtender ID="ajaxCount2Date" TargetControlID="txtCount2Date" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td>No. of Times Verification Done Count 3 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtNoOfTimesVerificationDoneCount3" runat="server" /> 
       </td> 
       <td>Count 3 Date 
       </td> 
       <td>: 
       </td> 
       <td> 
        <asp:TextBox ID="txtCount3" runat="server" /> 
        <ajax:CalendarExtender ID="ajaxCount3" TargetControlID="txtCount3" runat="server" /> 
       </td> 
      </tr> 

      <tr> 
       <td> 
        <asp:Button ID="btnSubmit" Text="Subimt" runat="server" OnClick="btnSubmit_Click" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <asp:Label ID="lblError" runat="server" /> 
       </td> 
      </tr> 
     </table> 
    </div> 

後面的代碼頁是:

protected void btnSubmit_Click(object sender, EventArgs e) 
    { 
     lblError.Text = "no code"; 
    } 

當我點擊提交按鈕,我得到兩個標籤錯誤和requiredfield驗證者

我得到的輸出是這樣的:

enter image description here

我不想用Requiredfield打後面的代碼提交事件驗證器

+0

你使用更新面板嗎?如果是這樣,你的標記的哪一部分在裏面? – Andrei

+0

@Andrei:OP正在使用'ajax:CalendarExtender',因此需要'ScriptManager'。我相信OP不使用任何更新面板。 – Prabhat

+0

默認情況下,不需要添加'EnableClientScript =「true」'它總是'true'。 – Prabhat

回答

0

我跑進魔女添加一個ScriptManager到網頁同樣的問題,打破了RequiredFieldValidator的驗證。我找到的解決方案是向ScriptManager添加一些ScriptReference。

<asp:ScriptManager ID="ScriptManager1" runat="server"> 
     <Scripts> 
      <asp:ScriptReference Name="jquery" /> 
      <asp:ScriptReference Path="~/Scripts/WebForms/WebUIValidation.js" /> 
     </Scripts> 
    </asp:ScriptManager> 

您的ScriptReference路徑和名稱可能與我的不同。