Oct 30, 2010, 10:51 PM
[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
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.csusing 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]