0

Using ASP-TextBox within html-table(td) within FormView EditItemTemplate, within ASP-Panel, within AJAX panel, within Content-page and within Master-Page, the ValidationSummary shows the wrong ErrorMessage when validating the textbox with the SAVE-button.

The ValSummary shows "Mileage entered is less than '<%= txtMileageRangeValidator.MinimumValue %>' miles".

And NOT "Mileage entered is less than 88123 miles"

The markup for the textbox and validator follows:

<asp:TextBox ID="txtMileage" runat="server" Text='<%# Bind("Mileage") %>' 
   CssClass="ucIsRequired"
   MaxLength="6" 
   AutoPostBack="True" OnTextChanged="txtMileage_TextChanged" 
/>
<asp:RangeValidator ID="txtMileageRangeValidator" runat="server" 
   ControlToValidate="txtMileage"
   Enabled="true"
   Display="None"
   MinimumValue='<%# Eval("aMileagePrev", "{0:D}")%>' 
   MaximumValue="999999"
   SetFocusOnError="false" 
   Type="Integer"
   ValidationGroup="valgrpDetails"
   ErrorMessage="Mileage entered is less than '<%= txtMileageRangeValidator.MinimumValue %>' miles"
   />

However, when the error appears in the ValidationSummary, it appears exactly as listed above -- it does not substitute the MinimumValue into the error-text.

What am I doing wrong? Thanks.

John D
  • 517
  • 7
  • 22

1 Answers1

0

Unless disabled, RangeValidators validate on the client side, i.e. no postback, so server side embedded script will not be re-rendered

If your going to reset the min value on the textbox event then you can set the ErrororMessage as you do for the MinimumValue but with a modified string format

ErrorMessage='<%# Eval("aMileagePrev", "Mileage entered is less than {0:D} miles") %>'

But something else now that I'm reading closer. A range validation is intended to check for a value being between min/max values. You're making an assumption that the value will never be greater than maxValue. If this is always the case then you would be better served with a CompareValidator with Type set to Integer and Operator set to LessThan

fnostro
  • 4,531
  • 1
  • 15
  • 23
  • Excellent answer !!!! works perfectly...Thanks. The max-length=6 therefore value cannot exceed 999999. I also thank you for your suggestion about the CompareValidator. Maybe you can assist with this question??? [link]http://stackoverflow.com/questions/27650321/user-control-retains-focus-incorrectly-after-textchanged-postback-when-uc-is-con – John D Jan 06 '15 at 12:48