[1.2] Postback on null values with autosave

  1. #1

    [1.2] Postback on null values with autosave

    Here is another variant of the postback issue. When you tab through the cells on a gridpanel with autosave, the cells with a null value will trigger an update of the database. But the cells with data will not trigger any update of the database and should not as expected since the data did not change.

    Steps to reproduce
    1) Create the sql table for the gridpanel (see sql script below)
    2) Add a couple of records with first name only
    3) Load the gridpanel below
    4) Click on the first row's first name
    5) Begin to tab through the cells
    6) The Last Name cells will trigger the database update/Autosave

            <ext:ResourceManager ID="ResourceManager1" runat="server">
            </ext:ResourceManager>
    
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Your_ApplicationConnectionString %>"
                SelectCommand="
    SELECT 
        ID_Person,
        NM_First,
        NM_Last,
        DT_Modified
    FROM 
        [HSA_Person]"
                UpdateCommand="
    UPDATE 
        [HSA_Person]
    SET 
        [NM_First] = @NM_First,
        [NM_Last] = @NM_Last,
        DT_Modified = Getdate()
    WHERE 
        [ID_Person] = @ID_Person"
    >
                <UpdateParameters>
                    <asp:Parameter Name="ID_Person" Type="Int32" />
                    <asp:Parameter Name="NM_First" Type="String" />
                    <asp:Parameter Name="NM_Last" Type="String" />
                </UpdateParameters>
            </asp:SqlDataSource>
    
            <ext:GridPanel ID="View1" Title="Listing" runat="server" Frame="true" Border="true" ColumnLines="True" height="220" width="450">
                <Store>
                    <ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1" AutoSave="True">
                        <Reader>
                            <ext:JsonReader IDProperty="ID_Person">
                                <Fields>
                                    <ext:RecordField Name="ID_Person" SortType="AsInt" />
                                    <ext:RecordField Name="NM_First" SortType="AsText" />
                                    <ext:RecordField Name="NM_Last" SortType="AsText" />
                                    <ext:RecordField Name="DT_Modified" SortType="AsDate" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>            
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column DataIndex="ID_Person" Header="ID" Width="50" Editable="False">
                        </ext:Column>
                        <ext:Column DataIndex="NM_First" Header="First Name" Tooltip="First Name" Width="100">
                            <Editor>
                                <ext:TextField ID="TextField1" runat="server">
                                </ext:TextField>
                            </Editor>
                        </ext:Column>
                        <ext:Column DataIndex="NM_Last" Header="Last Name" Tooltip="Last Name" Width="100">
                            <Editor>
                                <ext:TextField ID="TextField2" runat="server">
                                </ext:TextField>
                            </Editor>
                        </ext:Column>
                        <ext:DateColumn DataIndex="DT_Modified" Header="Last Updated" Format="MM/dd/yyyy HH:mm:ss" Width="150">
                        </ext:DateColumn>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
            </ext:GridPanel>
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    SET ANSI_PADDING ON
    GO
    
    CREATE TABLE [dbo].[HSA_Person](
    	[ID_Person] [int] IDENTITY(1,1) NOT NULL,
    	[NM_First] [varchar](50) NULL,
    	[NM_Last] [varchar](50) NULL,
    	[DT_Modified] [datetime] NULL,
     CONSTRAINT [PK_HSA_Person] PRIMARY KEY CLUSTERED 
    (
    	[ID_Person] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    
    SET ANSI_PADDING OFF
    GO
  2. #2
    If the field happens to be numberfield then you will get an error message.

    System.Exception: Input string was not in a correct format. ---> System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Convert.ToDecimal(String value, IFormatProvider provider) at System.String.System.IConvertible.ToDecimal(IFormatProvider provider) at System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) at System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) at System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) at System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) at System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) at Ext.Net.Store.MakeUpdates(IDataSource ds, XmlDocument xml) at Ext.Net.Store.MakeChanges() at Ext.Net.Store.DoSaving(String jsonData, XmlNode callbackParameters) --- End of inner exception stack trace --- at Ext.Net.Store.DoSaving(String jsonData, XmlNode callbackParameters) at Ext.Net.Store.RaiseAjaxPostBackEvent(String eventArgument)
    Last edited by geoffrey.mcgill; Dec 20, 2011 at 9:08 PM. Reason: please use [CODE] tags
  3. #3
    Hi,

    I would suggest you set up respective default values for the RecordFields.

    For example, for an int field you can set up "0" default value.
    <ext:RecordField Name="SomeIntField" Type="Int" DefaultValue="0" />
    It works when a field value is "undefined".

    When a field value can be, for example, null, please use Convert.
    <ext:RecordField Name="SomeIntField" Type="Int">
        <Convert Handler="if (value === null || typeof value === 'undefined') {
                              value = 0;
                          }
                          return value;" />
    </ext:RecordField>
    Last edited by Daniil; Jan 04, 2012 at 4:44 PM.
  4. #4
    Sometimes, there is informational value in null since you know that the field has been entered, answered, thought about, evaluated, and so on when a value is not null.

    Say that you are doing a survey and one value is zero, how do you know if you have a completed survey entry compared to a partial reply? With the default value, everyone would have answered the question that the data entry person would have entered into an application.
  5. #5
    You should be able to choose a different default value from 0, for example, "-777".
    Last edited by Daniil; Jan 09, 2012 at 9:36 PM.

Similar Threads

  1. Replies: 1
    Last Post: Jul 26, 2012, 1:18 PM
  2. datefield and null values
    By PetrSnobelt in forum 1.x Help
    Replies: 0
    Last Post: Jun 06, 2011, 10:51 AM
  3. [CLOSED] Keep values in Combo Box after postback
    By tjshin in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 29, 2010, 6:00 PM
  4. Store Object being set to null on postback
    By wh0urdady in forum 1.x Help
    Replies: 0
    Last Post: Jun 28, 2010, 6:20 PM
  5. Replies: 2
    Last Post: Jun 14, 2010, 2:47 PM

Posting Permissions