必填字段验证器

时间:2013-04-02 07:18:08

标签: asp.net

我是asp.net的新手,我正在设置必填字段验证器,它显示错误

错误是:

Unable to find control id 'txtFirstName' referenced by the 'ControlToValidate' property of 'RequiredFieldValidator1'. 

代码是:

 <tr>
            <td align="right" style="padding-right: 5px; width: 50%;">
                <asp:Label ID="lblFirstName" runat="server" Text="FIRSTNAME :"></asp:Label>
            </td>
            <td align="left" style="padding-left: 5px; width: 50%;">
                <asp:TextBox ID="txtFistName" runat="server" Width="70%"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtFirstName" ErrorMessage="You can't leave this empty."></asp:RequiredFieldValidator>
            </td>

        </tr>

可以帮助我解决这个问题......,

1 个答案:

答案 0 :(得分:2)

您在TextBox的ID中输入了错字号,您的标识为txtFistName而非txtFirstName,因此请进行更改。

更改

<asp:TextBox ID="txtFistName" runat="server" Width="70%"></asp:TextBox>

<asp:TextBox ID="txtFirstName" runat="server" Width="70%"></asp:TextBox>