Drop-down list and field check cause riot

For some reason, I cannot force the validator to raise the flag if something is wrong.

<asp:DropDownList ID="ddlTypeList" runat="server" DataSourceID="ods_TypeOptions" DataTextField="name" DataValueField="id" SelectedValue='<%# Bind("Type") %>' AppendDataBoundItems="true">
<asp:ListItem Text="-" Value="-1" Selected="True"></asp:ListItem> </asp:DropDownList>

The drop-down list has nice meanings, including the original layout.

Neither

<asp:RequiredFieldValidator ID="rfw" runat="server" ControlToValidate="ddlTypeList" InitialValue="-1" ToolTip="Required">*</asp:RequiredFieldValidator>

Nor

<asp:CompareValidator ID="cv" runat="server" ControlToValidate="ddlTypeList" ValueToCompare="-1" Operator="NotEqual" ToolTip="Required">*</asp:CompareValidator>

Raises any flags to say: "hey, you messed up, go fix it." For all google, searches, reviews, waving big hammers, I still have to figure out what I'm doing wrong.

I just want one solution to fix them all.

Oh yes, I also had ValidationGroup="myGroup" between DDL, RFV / CV and the button. Bad luck.

+4
source share
1 answer

Your code is correct. You must have a code element or markup that impedes validator functions. Is it possible that the ā€œ-ā€ element has its value changed from ā€œ-1ā€ to something else?

Make sure your button that submits the form has CausesValidation=True . Also make sure that the parent element of the validators is not set to Visible=False or that children will not be displayed on the page.

Ensure that the RequiredFieldValidator and CompareValidator displayed in the markup by searching for ā€œ_cvā€ or possibly ā€œcvā€ in the displayed markup. If it is not, then one of the parent elements will not be displayed or validators are deleted.

+1
source

All Articles