problems with form validation controls

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>


..
 
N

Nathan Sokalski

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top