Problem with AjaxControlToolkit CalendarExtender with TextChanged in a datagrid.
-
I have a datagrid with an CalendarExtender conected to a TextBox in a DataGrid
asp:datagrid id="dgSubscription" runat="server" CssClass="grid" AllowPaging="False" CellPadding="0" GridLines="Vertical" AutoGenerateColumns="False" ShowFooter="true" OnItemCreated="dgSubscription_ItemCreated"> Columns> asp:TemplateColumn HeaderText="Date" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px"> ItemTemplate> asp:TextBox ID="tbDtmStart" runat="server" AutoPostBack="true"></asp:TextBox> <cc1:CalendarExtender ID="ceStart" runat="server" Format="dd.MM.yyyy" TargetControlID="tbDtmStart" SelectedDate='<%#(DateTime)DataBinder.Eval(Container.DataItem, "dtmStart")%>'> </cc1:CalendarExtender>
I have an on item created in the code behind, hver I add a TextChanged event to the Date TextBoxprotected void dgSubscription_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Start date tb = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("tbDtmStart"); tb.TextChanged += new EventHandler(this.OnSubscriptionDtmStartChanged); .....
At first time the page load, the DataGrid.DataSource gets it values from a dataview. The problem is that theOnSubscriptionDtmStartChanged
is triggerd for every row in the DataGrid, because the CalendarExtender changes the TextBox's value. There is allso a problem that theOnSubscriptionDtmStartChanged
funtion i triggered 2 times when I change the value on one of the DataGridRow. I know that all of this has to do with the CalendarExtender changes the TextBox's value, but can I some how get around this? Thanks Thomas -
I have a datagrid with an CalendarExtender conected to a TextBox in a DataGrid
asp:datagrid id="dgSubscription" runat="server" CssClass="grid" AllowPaging="False" CellPadding="0" GridLines="Vertical" AutoGenerateColumns="False" ShowFooter="true" OnItemCreated="dgSubscription_ItemCreated"> Columns> asp:TemplateColumn HeaderText="Date" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px"> ItemTemplate> asp:TextBox ID="tbDtmStart" runat="server" AutoPostBack="true"></asp:TextBox> <cc1:CalendarExtender ID="ceStart" runat="server" Format="dd.MM.yyyy" TargetControlID="tbDtmStart" SelectedDate='<%#(DateTime)DataBinder.Eval(Container.DataItem, "dtmStart")%>'> </cc1:CalendarExtender>
I have an on item created in the code behind, hver I add a TextChanged event to the Date TextBoxprotected void dgSubscription_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Start date tb = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("tbDtmStart"); tb.TextChanged += new EventHandler(this.OnSubscriptionDtmStartChanged); .....
At first time the page load, the DataGrid.DataSource gets it values from a dataview. The problem is that theOnSubscriptionDtmStartChanged
is triggerd for every row in the DataGrid, because the CalendarExtender changes the TextBox's value. There is allso a problem that theOnSubscriptionDtmStartChanged
funtion i triggered 2 times when I change the value on one of the DataGridRow. I know that all of this has to do with the CalendarExtender changes the TextBox's value, but can I some how get around this? Thanks ThomasThe problem was that I binded the Date to the CalendarExtender as:
<cc1:CalendarExtender ID="ceStart" runat="server" Format="dd.MM.yyyy" TargetControlID="tbDtmStart" SelectedDate='<%#(DateTime)DataBinder.Eval(Container.DataItem, "dtmStart")%>'>
All of my problems went away when I insted:asp:TextBox ID="tbDtmStart" runat="server" Text='<%#((DateTime)DataBinder.Eval(Container.DataItem, "dtmStart")).ToString("dd.MM.yyyy")%>' AutoPostBack="true"></asp:TextBox> <cc1:CalendarExtender ID="ceStart" runat="server" Format="dd.MM.yyyy" TargetControlID="tbDtmStart"> </cc1:CalendarExtender>
Thomas