[CLOSED] NumberField postback error

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] NumberField postback error

    Hi,

    When using a number field if you enter 2 dots as the value (..) it breaks all direct methods and direct events for the page. We can obviously work around this by checking if the formpanels/fields are valid client side but we should be able to catch the error server side!

    Example code:

    Default.aspx:-
    <%@ Page CodeBehind="~/Default.aspx.cs" AutoEventWireup="true" Language="C#" Inherits="ext2testapp.Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="resMan" runat="server">
        </ext:ResourceManager>
        <form id="Form1" runat="server">
            <ext:NumberField runat="server" ID="test" />
            <ext:Button runat="server" ID="btnTest" Text="click me">
                <DirectEvents>
                    <Click OnEvent="btnClick" />
                </DirectEvents>
                <Listeners>
                    <Click Handler="#{DirectMethods}.stuff()" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Default.aspx.cs:-
    public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
    
            protected void btnClick(object sender, DirectEventArgs e)
            {
                var num = test.Value;
            }
    
            [DirectMethod]
            public void stuff()
            {
                var num = test.Value;
            }
        }
    the error throws in numberfieldbase in the checkrange function (via LoadPostData), it hits Double.Parse("..", nf) and then hits the catch which throws an error, but on postback we cant catch it, instead wouldn't it be better to mark the field as invalid server side and set the value to its empty value so it doesn't break eveything on a postback?
    Last edited by Daniil; Oct 12, 2012 at 6:09 AM. Reason: [CLOSED]
  2. #2
    If you update from 2.1 branch (http://svn.ext.net/premium/branches/2.1) then number field will fix the issue automatically (incorrect part of value (two dots and all symbols after two dots) will be removed)

    In any way, you can catch the exception in global error handler (in Global.asax), just set RethrowAjaxExceptions="true" for ResourceManager
  3. #3
    Second option, you can catch the error on the client side, use Failure handler of direct event
  4. #4
    I've just got the latest from the SVN and its still the same (revision 4395), if you run the example I gave it throws an exception within the catch:

    throw new InvalidCastException("The Text value supplied is not a type of Double. " + exception.Message);

    catching it in the global does work, but surely an invalid value in the field shouldn't break every direct method and event for the page?

    If you do the same with a DateField and type anything into it the value in the code behind its DateTime.MinValue which is what I would expect, but a number field just breaks everything....
  5. #5
    Please clarify Does nmber field reset invalid value on blur on your side?
    if not then what browser do you use?
  6. #6
    I'm not doing anything client side, I have no validation javascript side, if you run the example you will see the problem. On the direct event in the post event it sends up the value ".." for the number field which hits LoadPostData in Field.cs (Ext code) and when it hits CheckRange in NumberFieldBase.cs it throws an error when trying to parse ".." to a double.

    When you leave the number field on the client side it still shows as invalid, but since I have no validation client side as soon as anything hits the server it breaks because the Ext code fails to parse the string version of ".." which breaks all direct methods and events.
  7. #7
    Ok, clear
    We will make default behaviour as in DateField
  8. #8
    Please update from SVN and retest
  9. #9
    Quote Originally Posted by Vladimir View Post
    Please update from SVN and retest
    It works, but a couple of problems I have noticed:

    1. by entering a . as the value and then firing a direct it method replaces the control value with "-1.7976931348623157e+308" (double.MinValue), should this not update the control value client side? - not a major issue, by setting EmptyValue to 0 its fine anyway.
    2. setting EmptyValue from markup causes the error : "Cannot create an object of type 'System.Object' from its string representation '0' for the 'EmptyValue' property.", setting it from code behind works but any value that isn't a double causes it to throw an error as it hits "Convert.ToDouble(this.EmptyValue)", could it be set as a double instead of an object for the property?

    But I can work with it now to handle values server side so thanks!
  10. #10
    1. by entering a . as the value and then firing a direct it method replaces the control value with "-1.7976931348623157e+308" (double.MinValue), should this not update the control value client side? - not a major issue, by setting EmptyValue to 0 its fine anyway.
    The same behaviour like in DateField. If parsing is failed then EmptyValue is used

    2. setting EmptyValue from markup causes the error : "Cannot create an object of type 'System.Object' from its string representation '0' for the 'EmptyValue' property.", setting it from code behind works but any value that isn't a double causes it to throw an error as it hits "Convert.ToDouble(this.EmptyValue)", could it be set as a double instead of an object for the property?
    EmptyValue is defined in base class for Field widgets. Therefore type is object (widgets can use different types). ASP.NET doesn't support to set object types via markup. And for NumberField you have to use approperiate type (double) for EmptyValue because number field uses double only for a value
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: Jul 26, 2012, 1:18 PM
  2. Replies: 4
    Last Post: Jan 23, 2012, 11:31 AM
  3. Replies: 3
    Last Post: Mar 16, 2010, 1:50 PM
  4. [CLOSED] Javascript error on NumberField
    By jsemple in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 09, 2009, 3:56 PM
  5. [CLOSED] Postback Error With CardLayout
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 18, 2009, 10:22 AM

Posting Permissions