[CLOSED] Removing ViewState from ResourceManager is cleaning DateField value

  1. #1

    [CLOSED] Removing ViewState from ResourceManager is cleaning DateField value

    Hi,

    I've removed the ViewState from ResourceManager thru the RemoveViewState property.
    If I enter a value in a DateField, depending on the month (ex: January), the value is not being sent to the server (it's 01/01/0001'.

    If a remove the property "RemoveViewState" from the ResourceManager, everything works again.

    My regional settings are DD/MM/YYYY

    Here is the code:

    Periods.aspx
    <%@ Page language="c#" CodeFile="Periods.aspx.cs" AutoEventWireup="true" Inherits="Maintenances_Periods"%>
    <%@ Import Namespace="WHTS.Business.Core" %>
    <%@ Import Namespace="WHTS.Common.Classes" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Src="~/Maintenances/UserControls/ucPeriodsEdit.ascx" TagName="ucPeriodsEdit" TagPrefix="uc" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head id="Head1" runat="server">
        <title>Periods</title>
        <script language="javascript" src="../Scripts/CooliteScripts.js" type="text/javascript"></script>    
    </head>
    <body>            
        <script language="javascript" type="text/javascript">
            var strRetrievingData = '<%=TranslationsBsn.TranslateText("The data could not be retrieved") %>';
    
            function init() {
                resizeGrid(grdItems);
            }
    
            var applyFilters = function () {
                pagToolbar.changePage(1);
            }
    
            var renderShortDate = function (value) {
                if (value != '')
                    return value.dateFormat('<%=DateTimeHelper.GetCooliteShortDateFormat2()%>');
                else
                    return '';
            }
        </script>        
        <form id="frmPeriods" runat="server">
            <ext:ResourceManager ID="smManager" runat="server" RethrowAjaxExceptions="true" RemoveViewState="true">
                <Listeners>
                    <WindowResize Handler="init();" />
                    <DocumentReady Handler="init();Date.useStrict = true;" />
                </Listeners>
            </ext:ResourceManager>
            <ext:Store runat="server" ID="stData" AutoLoad="true" RemoteSort="true" OnRefreshData="stData_RefreshData" >
                <Proxy>
                    <ext:PageProxy />
                </Proxy>
                <Reader>
                    <ext:JsonReader IDProperty="ID" >
                        <Fields>
                            <ext:RecordField Name="ID" />
                            <ext:RecordField Name="Location" ServerMapping="Location.Description" Type="String" />
                            <ext:RecordField Name="ClosingDate" Type="Date" />
                            <ext:RecordField Name="PaymentDate" Type="Date" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <SortInfo Field="ClosingDate" Direction="ASC" />
                <AutoLoadParams>
                    <ext:Parameter Name="start" Value="0" Mode="Raw" />
                    <ext:Parameter Name="limit" Value="25" Mode="Raw" />
                    <ext:Parameter Name="sort" Value="" />
                    <ext:Parameter Name="dir" Value="" />
                </AutoLoadParams>
                <Listeners>
                    <LoadException Handler="Ext.MessageBox.alert(response.statusText, strRetrievingData);" />
                </Listeners>
            </ext:Store>
            
            <ext:Store runat="server" ID="stLocations" AutoLoad="true" >
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ID" />
                            <ext:RecordField Name="Description" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <Listeners>
                    <Load Handler="#{cmbLocations}.setValue(this.getAt(0).data[#{cmbLocations}.valueField]);" Single="false" />
                </Listeners>
            </ext:Store>
            <ext:GridPanel runat="server"  ID="grdItems" StoreID="stData" Title="Periods" Header="false" AutoWidth="true"  TrackMouseOver="true" AutoExpandColumn="clmLocation">                  
                <CustomConfig>
                    <ext:ConfigItem Name="keyMap" Value="{}" Mode="Raw" />
                </CustomConfig>
                <View>
                    <ext:GridView  SortAscText="Asc Order" SortDescText="Desc Order" ColumnsText="Columns">
                        <GetRowClass Fn="rowClassAlternateColor" />
                        <HeaderRows>
                            <ext:HeaderRow>
                                <Columns>
                                    <ext:HeaderColumn AutoWidthElement="false">
                                        <Component>
                                            <ext:Button ID="btnApplyFilters" runat="server" Icon="Zoom" ToolTip="Search">
                                                <Listeners>
                                                    <Click Handler="applyFilters();" />
                                                </Listeners>
                                            </ext:Button>
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn Cls="x-small-editor">
                                        <Component>
                                            <ext:ComboBox ID="cmbLocations" runat="server" StoreID = "stLocations" Mode = "Local" DisplayField = "Description" ValueField="ID" EnableKeyEvents="true" >
                                                <Listeners>
                                                    <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){applyFilters();e.stopEvent();}" />
                                                </Listeners>
                                            </ext:ComboBox>
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn Cls="x-small-editor">
                                        <Component>
                                            <ext:DateField ID="dpClosingDate" runat="server" EnableKeyEvents="true" >
                                                <Listeners>
                                                    <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){applyFilters();e.stopEvent();}" />
                                                </Listeners>
                                            </ext:DateField>
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn Cls="x-small-editor">
                                        <Component>
                                            <ext:DateField ID="dpPaymentDate" runat="server" EnableKeyEvents="true" >
                                                <Listeners>
                                                    <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){applyFilters();e.stopEvent();}" />
                                                </Listeners>
                                            </ext:DateField>
                                        </Component>
                                    </ext:HeaderColumn>
                                </Columns>
                            </ext:HeaderRow>
                        </HeaderRows>
                    </ext:GridView>
                </View>
                <SelectionModel>
                    <ext:RowSelectionModel ID="rowSelMode1" runat="server"></ext:RowSelectionModel>
                </SelectionModel>                   
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:CommandColumn Width="30" ColumnID="clmEdit">
                            <Commands>
                                <ext:GridCommand Icon="NoteEdit" CommandName="cmdEdit" ToolTip-Text="Edit" />
                            </Commands>
                        </ext:CommandColumn>
                        <ext:Column ColumnID="clmLocation" Header="Country" DataIndex="Location" Width="130" align="Left" Sortable="true" Hideable="false" />
                        <ext:Column ColumnID="clmClosingDate" Header="Closing Date" DataIndex="ClosingDate" Width="100" align="Right" Sortable="true" >
                            <Renderer Fn="renderShortDate" />
                        </ext:Column>
                        <ext:Column ColumnID="clmPaymentDate" Header="Payment Date" DataIndex="PaymentDate" Width="100" align="Right" Sortable="true" >
                            <Renderer Fn="renderShortDate" />
                        </ext:Column>
                    </Columns>
                </ColumnModel>                
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <BottomBar>                                           
                    <ext:PagingToolBar ID="pagToolbar" runat="server"  PageSize="25" StoreID="stData" EmptyMsg ="No data to show">
    
                        <Items>
                            <ext:ToolbarSeparator />
                            <ext:Button ID="btnAddNew" runat="server" Text="New Period" StandOut="true" Icon="Add" ToolTip="Add New Period">
                                <DirectEvents>
                                    <Click OnEvent="ShowDetails" Failure="Ext.MessageBox.alert(response.statusText, strRetrievingData);">
                                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{grdItems}.body}" />
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="0" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:PagingToolBar>
                </BottomBar>                                                    
                <DirectEvents>
                    <Command OnEvent="ShowDetails" Failure="Ext.MessageBox.alert(response.statusText, strRetrievingData);">
                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{grdItems}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="params[1].id" Mode="Raw" />
                        </ExtraParams>
                    </Command>
                </DirectEvents>    
            </ext:GridPanel>            
            <uc:ucPeriodsEdit ID="ucPeriodsEdit" runat="server"/>
            <ext:Hidden ID="hidCountFilter" runat="server" />
            <ext:Hidden ID="hidOldFilter" runat="server" />
        </form>
    </body>
    </html>
    Periods.aspx.cs
    using System;
    using System.Collections;
    using Ext.Net;
    using System.Collections.Generic;
    using WHTS.Business.Security;
    using WHTS.Business.Core;
    using WHTS.Common.Classes;
    using WHTS.Common.Entities;
    using WHTS.Web.Pages;
    
    public partial class Maintenances_Periods : ContextPage
    {
        #region Events Controllers
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            Response.Clear();
            Response.CacheControl = "Private";
            Response.Expires = 0;
    
            if (!IsPostBack)
            {
                dpClosingDate.Format = DateTimeHelper.GetCooliteShortDateFormat();
                dpPaymentDate.Format = DateTimeHelper.GetCooliteShortDateFormat();
                dpClosingDate.InvalidText = "You must enter a valid date with this format: " + DateTimeHelper.GetCooliteShortDateFormat();
                dpPaymentDate.InvalidText = "You must enter a valid date with this format: " + DateTimeHelper.GetCooliteShortDateFormat();
            }
    
            this.ucPeriodsEdit.Grid = grdItems;
    
            if (!X.IsAjaxRequest)
            {
                LoadDDLocations();
            }
        }
    
        protected void stData_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            int intStart = e.Start;
            bool blnSortASC = true;
            string strSortProperty = e.Sort;
    
            if (e.Start >= e.Limit)
                intStart = (int)Math.Floor(Convert.ToDecimal(e.Start) / e.Limit);
    
            if (Convert.ToString(e.Dir).ToUpper() != "ASC")
                blnSortASC = false;
    
            intStart++;
    
            if (strSortProperty.ToUpper() == "LOCATION")
                strSortProperty = "propLocation.Description";
    
            LoadGrid(strSortProperty, blnSortASC, intStart, e.Limit);
        }
    
        #endregion
    
        #region Functions
    
        private void LoadDDLocations()
        {
            try
            {
                IList ilstLocations = SecurityBsn.CurrentUserLocations((int)Location.eLocationLevels.Country);
    
                Location objLocation = new Location();
    
                objLocation.Description = TranslationsBsn.TranslateText("All");
    
                ilstLocations.Insert(0, objLocation);
    
                stLocations.DataSource = ilstLocations;
                stLocations.DataBind();
            }
            catch (ApplicationException ex)
            {
                ResourceManager.AjaxSuccess = false;
                ResourceManager.AjaxErrorMessage = TranslationsBsn.TranslateText(ex.Message);
            }
        }
    
        private void LoadGrid(string strSortField, bool blnSortASC, int intPageIndex, int intPageSize)
        {
            try
            {
                Nullable<Guid> guiLocation = null;
                Nullable<DateTime> datClosingDate = null;
                Nullable<DateTime> datPaymentDate = null;
    
                if (cmbLocations.SelectedIndex > 0)
                    guiLocation = new Guid(cmbLocations.SelectedItem.Value);
    
                if (Convert.ToDateTime(dpClosingDate.Value) != DateTime.MinValue)
                    datClosingDate = Convert.ToDateTime(dpClosingDate.Value);
    
                if (Convert.ToDateTime(dpPaymentDate.Value) != DateTime.MinValue)
                    datPaymentDate = Convert.ToDateTime(dpPaymentDate.Value);
    
                IList<Period> ilstItems = new PeriodsBsn().GetByFilter(guiLocation
                    , datClosingDate
                    , datPaymentDate
                    , strSortField
                    , blnSortASC
                    , intPageIndex
                    , intPageSize);
    
                stData.DataSource = ilstItems;
                stData.DataBind();
    
                string strNewFilters = guiLocation + "-" + datClosingDate + "-" + datPaymentDate + "-";
    
                if (hidOldFilter.Text != strNewFilters)
                {
                    hidOldFilter.Text = strNewFilters;
                    hidCountFilter.Value = new PeriodsBsn().GetCountByFilter(guiLocation
                        , datClosingDate
                        , datPaymentDate).ToString();
                }
    
                (stData.Proxy[0] as PageProxy).Total = Convert.ToInt32(hidCountFilter.Value);
            }
            catch (ApplicationException ex)
            {
                Ext.Net.ResourceManager.AjaxSuccess = false;
                Ext.Net.ResourceManager.AjaxErrorMessage = TranslationsBsn.TranslateText(ex.Message);
            }
        }
    
        protected void ShowDetails(object sender, DirectEventArgs e)
        {
            try
            {
                string id = e.ExtraParams["id"];
                Period period = null;
    
                if (id != "" && id != "0")
                    period = new PeriodsBsn().Get(new Guid(id));
    
                this.ucPeriodsEdit.ResourceManager = smManager;
                this.ucPeriodsEdit.Period = period;
                this.ucPeriodsEdit.Show();
    
                hidOldFilter.Value = "";
            }
            catch (ApplicationException ex)
            {
                Ext.Net.ResourceManager.AjaxSuccess = false;
                Ext.Net.ResourceManager.AjaxErrorMessage = TranslationsBsn.TranslateText(ex.Message);
            }
        }
    
        #endregion
    }
    Thanks
    Last edited by Daniil; Nov 04, 2010 at 8:27 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Unfortunately, your sample is not compilable. I cannot reproduce the issue after removing none compalible code
  3. #3
    Vladimir,

    I've created a compilable sample, but I don't know how to post it, because it has 4 MB.
    Can you give me more disk quota or an alternative email address ?

    Thanks,
    Ariel
    Attached Thumbnails Click image for larger version. 

Name:	Periods.jpg 
Views:	121 
Size:	63.9 KB 
ID:	1817  
  4. #4
    Hi,

    Please do not include any assemblies. Also, you can send your test project to the support email (support@object.net)
    Last edited by geoffrey.mcgill; Nov 04, 2010 at 3:41 AM.
  5. #5
    Hi azstern,

    Please clarify is this still an issue? Should we mark this thread as closed?

    Note: there is no test project on support@object.net from you.
  6. #6
    Daniil

    No, the current status still pending.

    Let me forward the email to support@object.net

    Thanks.
    Ariel
    Last edited by geoffrey.mcgill; Nov 04, 2010 at 3:41 AM.
  7. #7
    Hi,

    I did not test your application but I think that know where the problem.
    You set Format (in the FormatScreen method of ucPeriodsEdit user control) only if not IsPostBack.
    If you change the Format then you have to set it for each request for correct converting of submitted data (when you use ViewState the format is restored from ViewState automatically)

    Therefore change Page_Load likes this
     protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
              hidId.Value = "-1";          
        }
        FormatScreen();
    }
    private void FormatScreen()
            {
                if(X.IsAjaxRequest)
                {
                    dpClosingDate.SuspendScripting();
                    dpPaymentDate.SuspendScripting();
                }
                dpClosingDate.Format = DateTimeHelper.GetCooliteShortDateFormat();
                dpClosingDate.AltFormats = " ";
                dpPaymentDate.Format = DateTimeHelper.GetCooliteShortDateFormat();
                dpPaymentDate.AltFormats = " ";
                dpClosingDate.InvalidText = "You must enter a valid date with this format: " + DateTimeHelper.GetCooliteShortDateFormat();
                dpPaymentDate.InvalidText = "You must enter a valid date with this format: " + DateTimeHelper.GetCooliteShortDateFormat();
                if(X.IsAjaxRequest)
                {
                    dpClosingDate.ResumeScripting();
                    dpPaymentDate.ResumeScripting();
                }
            }
  8. #8
    Hi Vladimir,
    I made the change you suggested, but it still doesn't work. The server gets '01/01/0001'

    Thanks.
    Ariel
  9. #9
    Hi,

    I forgot that FormatScreen method should be moved to Page_Init because Format property must be set before LoadPostData
     protected void Page_Init(object sender, EventArgs e)
            {
                FormatScreen();
            }
  10. #10
    Yes, it solved the problem, thanks Vladimir .

Similar Threads

  1. [CLOSED] Cleaning up memory with tab panels
    By PhilG in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 12, 2012, 9:17 AM
  2. [CLOSED] removing cells from rowlayout
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Jun 17, 2011, 11:46 AM
  3. [CLOSED] .rejectChanges not removing an added row
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 27, 2011, 3:15 PM
  4. [CLOSED] Removing and Re-adding ResourceManager
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 08, 2010, 11:32 AM
  5. [CLOSED] Focus removing on Grid
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 27, 2009, 4:49 AM

Posting Permissions