CompareValidator problem

A

Axel Dahmen

Hi,

I've got the same problem as described below. No answer found yet. Can
someone please help? (I'm using .NET 1.0 on my development machine and 1.1
on my webserver. Like Susanna, I only get the error on my webserver.)

TIA,
Axel Dahmen

--
I used compare validator control "ValueToCompare" in my aspx file like
this:

<asp:comparevalidator id="CompareValidator1" runat="server"
CssClass="image-caption" ValueToCompare="500,000.00"
Operator="LessThanEqual" Type="Currency" ErrorMessage="Tast inn et
tall som ikke er høyere enn 500000!" Display="Dynamic"
ControlToValidate="txtLaneSum" Text=""></asp:comparevalidator>


And it works fine on my development server. but when I have installed
this .NET application to the production server, I can not get the
ASP.NET page to work. I am given an error message as the following:

Server Error in / Application
The value '500,000.00' of the ValueToCompare property of
'CompareValidator1' cannot be converted to type 'Currency'.
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 '500,000.00' of
the ValueToCompare property of 'CompareValidator1' cannot be converted
to type 'Currency'.

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 '500,000.00' of the
ValueToCompare property of 'CompareValidator1' cannot be converted to
type 'Currency'.]
System.Web.UI.WebControls.CompareValidator.ControlPropertiesValid()
+415
System.Web.UI.WebControls.BaseValidator.Render(HtmlTextWriter
writer) +85
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
writer) +44
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
+395
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1900


Any ideas/help you can offer would be greatly appreciated.

Thanks
Susanna Chen
 
P

Peter Blum

The current culture of the web form is used to convert from the string
"500,000.00" to a decimal value. If that culture treats "," as a decimal
place and period as a thousands separator (like many countries do), you will
get that error. Most likely your server is setup with a different default
culture than your development computer.

See the System.Globalization.CultureInfo object documention for an overview
of cultures.

See the <@ Page Culture= > attribute for setting a culture on one page.
You can also set the culture in the current thread:
System.Threading.Thread.CurrentCulture = [your CultureInfo object]

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Axel Dahmen said:
Hi,

I've got the same problem as described below. No answer found yet. Can
someone please help? (I'm using .NET 1.0 on my development machine and 1.1
on my webserver. Like Susanna, I only get the error on my webserver.)

TIA,
Axel Dahmen

--
I used compare validator control "ValueToCompare" in my aspx file like
this:

<asp:comparevalidator id="CompareValidator1" runat="server"
CssClass="image-caption" ValueToCompare="500,000.00"
Operator="LessThanEqual" Type="Currency" ErrorMessage="Tast inn et
tall som ikke er høyere enn 500000!" Display="Dynamic"
ControlToValidate="txtLaneSum" Text=""></asp:comparevalidator>


And it works fine on my development server. but when I have installed
this .NET application to the production server, I can not get the
ASP.NET page to work. I am given an error message as the following:

Server Error in / Application
The value '500,000.00' of the ValueToCompare property of
'CompareValidator1' cannot be converted to type 'Currency'.
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 '500,000.00' of
the ValueToCompare property of 'CompareValidator1' cannot be converted
to type 'Currency'.

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 '500,000.00' of the
ValueToCompare property of 'CompareValidator1' cannot be converted to
type 'Currency'.]
System.Web.UI.WebControls.CompareValidator.ControlPropertiesValid()
+415
System.Web.UI.WebControls.BaseValidator.Render(HtmlTextWriter
writer) +85
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
writer) +44
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
+395
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1900


Any ideas/help you can offer would be greatly appreciated.

Thanks
Susanna Chen
 
A

Axel Dahmen

Hi, Peter,

unfortunately this is not the case. I have this problem with both, English
as well as German formatted prices. In the meantime I've found out that my
webserver converts SQL SMALLMONEY values into decimal values having a 4
digit precision. This value irritates the Validator. Here's an exact
description of the problem:
http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=214327

Any help is quite appreciated!

TIA,
Axel Dahmen

--------------------
Peter Blum said:
The current culture of the web form is used to convert from the string
"500,000.00" to a decimal value. If that culture treats "," as a decimal
place and period as a thousands separator (like many countries do), you will
get that error. Most likely your server is setup with a different default
culture than your development computer.

See the System.Globalization.CultureInfo object documention for an overview
of cultures.

See the <@ Page Culture= > attribute for setting a culture on one page.
You can also set the culture in the current thread:
System.Threading.Thread.CurrentCulture = [your CultureInfo object]

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Axel Dahmen said:
Hi,

I've got the same problem as described below. No answer found yet. Can
someone please help? (I'm using .NET 1.0 on my development machine and 1.1
on my webserver. Like Susanna, I only get the error on my webserver.)

TIA,
Axel Dahmen

--
I used compare validator control "ValueToCompare" in my aspx file like
this:

<asp:comparevalidator id="CompareValidator1" runat="server"
CssClass="image-caption" ValueToCompare="500,000.00"
Operator="LessThanEqual" Type="Currency" ErrorMessage="Tast inn et
tall som ikke er høyere enn 500000!" Display="Dynamic"
ControlToValidate="txtLaneSum" Text=""></asp:comparevalidator>


And it works fine on my development server. but when I have installed
this .NET application to the production server, I can not get the
ASP.NET page to work. I am given an error message as the following:

Server Error in / Application
The value '500,000.00' of the ValueToCompare property of
'CompareValidator1' cannot be converted to type 'Currency'.
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 '500,000.00' of
the ValueToCompare property of 'CompareValidator1' cannot be converted
to type 'Currency'.

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 '500,000.00' of the
ValueToCompare property of 'CompareValidator1' cannot be converted to
type 'Currency'.]
System.Web.UI.WebControls.CompareValidator.ControlPropertiesValid()
+415
System.Web.UI.WebControls.BaseValidator.Render(HtmlTextWriter
writer) +85
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
writer) +44
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
+395
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1900


Any ideas/help you can offer would be greatly appreciated.

Thanks
Susanna Chen
 
P

Peter Blum

Be sure to do any number to string conversion using the same CultureInfo
object used by validators. That would be in
System.Threading.Thread.CurrentCulture.

For example, do convert a decimal value in 'val', pass the culture in
ToString()

decimal val = 32.12;
string vFormattedVal = val.ToString(System.Threading.Thread.CurrentCulture)

If this is the correct answer, may I recommend you post a solution to your
thread on gotdotnet so others involved know the results.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
A

Axel Dahmen

Thanks, Peter,

actually the correct answer would be that my webserver converts val into a
string having a precision of 4 digits. If you pass 32.12 to val, ToString()
yields "32.1200". The Validator is not able to convert this value into a
Currency value because of the two trailing zeros.

I've set the correct culture in Page_Init() so the culture is not the
problem here. After changing val.ToString() into val.ToString("F2")
everything works fine. However, one question remains: Why does my
development machine convert 32.12 into "32.12" whereas my webserver converts
it into "32.1200"...

I've posted my solution to GetDotNet. Still I'm curious how I can force my
webserver to behave like my development computer and vice versa. As long as
they behave differently I can't avoid missing errors during testing and
debugging.

regards,
Axel Dahmen



-------------------------
 

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

Forum statistics

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

Latest Threads

Top