G
Guest
Hi, I have a text box with corresponding comparevalidator as so..
<tr><td align="right">End Date :</td>
<td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration"
autopostback="true" cssClass="mandatory"/></td>
<td><asp:CompareValidator id="vdEndDate" runat="server"
cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date"
Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/>
</td></tr>
As you can see when the user changes the text in dtEndDate, i want some code
to fire. However I only want this code to fire if they have entered a correct
date format, tested by vdEndDate, my validator control. So in my script to
fire I have this:
public void set_Duration(Object sender, EventArgs e) {
if (vdEndDate.IsValid) {
blah blah
}
}
But when i put in a silly date and exit the field, the code still fires and
errors coz my date format is wrong for the code i've written. Why is it not
escaping the if condition?? I even see the validator control error message
pop up briefly before it bombs. So surely vdEndDate is not valid when it
enters my code????
<tr><td align="right">End Date :</td>
<td><asp:TextBox id="dtEndDate" runat="server" onTextChanged="set_Duration"
autopostback="true" cssClass="mandatory"/></td>
<td><asp:CompareValidator id="vdEndDate" runat="server"
cssClass="ErrorMessage" ControlToValidate="dtEndDate" Type="Date"
Operator="DataTypeCheck" ErrorMessage="Incorrect date format"/>
</td></tr>
As you can see when the user changes the text in dtEndDate, i want some code
to fire. However I only want this code to fire if they have entered a correct
date format, tested by vdEndDate, my validator control. So in my script to
fire I have this:
public void set_Duration(Object sender, EventArgs e) {
if (vdEndDate.IsValid) {
blah blah
}
}
But when i put in a silly date and exit the field, the code still fires and
errors coz my date format is wrong for the code i've written. Why is it not
escaping the if condition?? I even see the validator control error message
pop up briefly before it bombs. So surely vdEndDate is not valid when it
enters my code????