4

For some reason, I can't get the validator to raise a flag when I do things 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 values, incl the initial dummy.

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 - u messed up, go fix it". For all the google, searching, reviews, swinging big hammers, I have yet to spot what I am doing wrong.

I just want one solution to fix them all.

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

DoStuffZ
  • 785
  • 15
  • 37
  • Copy and past this into a solution and it works preaty fine. Have you tried using it outside of the parent data control to know if this works correctly? Because, dunno exactly why but maybe its because of your `SelectedValue='<%# Bind("Type") %>' `. BTW, just saw that it do not validate it on Page_Load but if you try to do a postback on a button who have the same validation group, it should validate it. – Simon Dugré Jun 09 '11 at 20:11

1 Answers1

1

Your code is correct. You must have some element of code or markup that is obstructing the functionality of the validator. Is it possibly that the "-" item has its value changed from "-1" to something else?

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

Verify that the RequiredFieldValidator and CompareValidator are rendering in the markup by searching for "_cv" or possibly "cv" in the outputted markup. If it is not there, then one of the parent elements is not being rendered or the validators are being deleted.

Devin Burke
  • 13,642
  • 12
  • 55
  • 82