2016-01-25 121 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路径和名称可能与我的不同。