Hello,
I was wondering why the following is happening. I have a page with a DatePicker. I set the OnSelectedDateChanged event. All works fine. Autopostback is also set. A grid then gets rebound (calling grid.rebind in datechange event) to reflect new date range selection. Now I have a button on the form, which then triggers an action based on the selected items in the grid. All works fine when viewstate is enabled for both datepicker and grid.
But when I set the EnableViewState to false for the datepicker, all goes wrong. Because the viewstate on the datepicker is turned off, the OnSelectedDateChanged is not just fired when the date changes, but also when I click the button, or trigger any other server side event. This cause the grid to be rebound and my SelectedItems count is then zero.
Is this normal behavior and my understanding of viewstate is too limited? Since I dont need viewstate on datepicker just to rebind grid to correct date, I would prefer to leave viewstate off.
Example page to see the OnSelectedDateChanged event getting fired when viewstate is disabled on the datepicker and you trigger another event: (just enable viewstate on datepicker to see that event doesnt get triggered then if button is clicked)
ASPX:
Code-behind:
I was wondering why the following is happening. I have a page with a DatePicker. I set the OnSelectedDateChanged event. All works fine. Autopostback is also set. A grid then gets rebound (calling grid.rebind in datechange event) to reflect new date range selection. Now I have a button on the form, which then triggers an action based on the selected items in the grid. All works fine when viewstate is enabled for both datepicker and grid.
But when I set the EnableViewState to false for the datepicker, all goes wrong. Because the viewstate on the datepicker is turned off, the OnSelectedDateChanged is not just fired when the date changes, but also when I click the button, or trigger any other server side event. This cause the grid to be rebound and my SelectedItems count is then zero.
Is this normal behavior and my understanding of viewstate is too limited? Since I dont need viewstate on datepicker just to rebind grid to correct date, I would prefer to leave viewstate off.
Example page to see the OnSelectedDateChanged event getting fired when viewstate is disabled on the datepicker and you trigger another event: (just enable viewstate on datepicker to see that event doesnt get triggered then if button is clicked)
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableScriptCombine="true" OutputCompression="Forced" ScriptMode="Release"> <Scripts> <%--Needed for JavaScript IntelliSense in VS2010--%> <%--For VS2008 replace RadScriptManager with ScriptManager--%> <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" /> </Scripts> </telerik:RadScriptManager> <div> <asp:Button runat="server" ID="btnSelect" Text="Select" OnClick="btnSelect_Click" /> <telerik:RadDatePicker ID="dp4" runat="server" MinDate="2006-01-01" AutoPostBack="True" OnSelectedDateChanged="dp4_Changed" Width="100px" EnableViewState="False"> <Calendar ID="cal1" runat="server" /> <DateInput ID="dip1" runat="server"> </DateInput> </telerik:RadDatePicker> </div> </form></body></html>Code-behind:
using System;using Telerik.Web.UI.Calendar;public partial class Test : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void btnSelect_Click(object sender, EventArgs e) { } protected void dp4_Changed(object sender, SelectedDateChangedEventArgs e) { //set breakpoint string x = ""; }}