problems with form validation controls

  • Thread starter Thread starter merrittr
  • Start date Start date
M

merrittr

I have the following validator control:


<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="Purchase_Date"
ErrorMessage="Invalid Date" MaximumValue="1/01/2222"
MinimumValue="1/01/1970"></asp:RangeValidator>


I am trying to use it to validate a textbox in a form view however I
get the message:


Unable to find control id 'Purchase_Date' referenced by the
'ControlToValidate' property of 'RangeValidator1'
but as far as i can see I have the ID of the textbox?????

<asp:FormView ID="FormView1" runat="server"
DataSourceID="SqlDataSource1" DefaultMode="Insert" >

<asp:TextBox ID="Purchase_Date" runat="server" Text='<%#
Bind("Purchase_Date", "{0:d}") %>' ></asp:TextBox>


..
 
I haven't seen your entire code, but based on what you have included in your
posting it looks to me like the reason is because of the fact that the
TextBox is inside a FormView and the RangeValidator is not. Try doing one of
the following (I do normally use FormView, but I think one of these might
work):

1. Place the RangeValidator inside the FormView.

OR

2. Assign the ControlToValidate property programmatically in the Load event.
You will need to use the FindControl() method and convert it to a TextBox in
order to do this.

Hopefully one of these works. Good Luck!
 
Back
Top