We help IT Professionals succeed at work.
Get Started

How do I dynamically load min/max properties of the asp:RangeValidator?

jxbma
jxbma asked
on
1,112 Views
Last Modified: 2012-05-09
Hi:

Relatively newby to the world of ASP .Net.

I'm having issues trying to set the min/max values of the RangeValidator.
I'm trying to set these values dynamically as my page/control loads.
I'd like to set these values directly within the page using embedded JavaScript to
references variables from my code behind.



My ASP .Net code looks like this:
=======================

<asp:RangeValidator ID="rngNumberOfTravelers" runat="server"  
ControlToValidate="tNumberofTravelers"
ErrorMessage="<%=RangeTravelersErrorMessage%>"
CssClass="error"
Display="Dynamic"
EnableClientScript="true"  
MinimumValue="<%=MinNumber%>"
MaximumValue="<%=MaxNumber%>"  
Type="Integer"/>


My property definition is C# looks like this:
==============================

    private int _minNumber;
    public int MinNumber
    {
        get {
                return _minNumbers;
            }
    }
    private int _maxNumber;
    public int MaxNumber
    {
        get {
                return _maxNumbers;
            }
    }


I get the following exception during the page load:
===================================

Server Error in '/Explorica.TravelerAdmin' Application.
--------------------------------------------------------------------------------

The value '<%=MaxNumberofTravelers%>' of the MaximumValue property of 'rngNumberOfTravelers' cannot be converted to type 'Integer'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The value '<%=MaxNumberofTravelers%>' of the MaximumValue property of 'rngNumberOfTravelers' cannot be converted to type 'Integer'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

[HttpException (0x80004005): The value '<%=MaxNumberofTravelers%>' of the MaximumValue property of 'rngNumberOfTravelers' cannot be converted to type 'Integer'.]
   System.Web.UI.WebControls.RangeValidator.ValidateValues() +2564459
   System.Web.UI.WebControls.RangeValidator.ControlPropertiesValid() +18
   System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +146
   System.Web.UI.Control.PreRenderRecursiveInternal() +113
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4185



What am I doing wrong?
Can this not be set dynamically on the ASPX page?

I've also tried setting this in my code behind during Page_Load() <Binding the controls>.
But the result was that my RangeValidator did not fire correctly.


Any and all help will be much appreciated.

Thanks,
JohnB
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE