简体   繁体   中英

ControlToValidate doesn't work

I'm trying to add RequiredFieldValidator behind the <input> .

The following is my code:

<form id="form1" runat="server">
    <div>
        <input type="text" id="MID" />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
            runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
        <br />
    </div>
</form>

Then, I'm trying to assign the ControlToValidate to be MID, which is the id of the input text. However, there isn't anything available in the ControlToValidate:

在此处输入图片说明

Then, I just type MID in it and run the program,

<form id="form1" runat="server">
    <div>
        <input type="text" id="MID" />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
            runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="MID"></asp:RequiredFieldValidator>
        <br />
    </div>
</form>

and I get this:
在此处输入图片说明

It's been about 5 or 6 years since I last wrote an ASP.Net website, but I'm sure you can only use server side validators on server side input controls. Your form doesn't contain any server side input controls.
Your <input type="text" id="MID" /> should be an asp:TextBox tag.

runat="server"添加到输入元素或使用ASP.NET TextBox控件( asp:TextBox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM