必需的字段验证程序不使用AjaxControlToolkit

时间:2016-01-25 09:40:22

标签: asp.net ajaxcontroltoolkit requiredfieldvalidator

这是我的代码

<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 validatiors

我得到的输出是这样的:

enter image description here

我不想使用Requiredfield验证器

来查看代码背后的提交事件

1 个答案:

答案 0 :(得分:0)

我在向页面添加ScriptManager时遇到了同样的问题,打破了RequiredFieldValidator验证。我找到的解决方案是在ScriptManager中添加一些ScriptReferences。

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

您的ScriptReference路径和名称可能与我的不同。