I am using RadTabStrip as a wizard.
On one of the page views I have usercontrol that loads a grid. I calculate the footer total on one of the columns in ItemDatabound event.
If I move to a previous tab and then come back to the tab with the grid, I notice that my Itemdatabound event is called twice and henece my total gets doubled up.
I can't figure out why the ItemdataBound event is fired twice.
On one of the page views I have usercontrol that loads a grid. I calculate the footer total on one of the columns in ItemDatabound event.
If I move to a previous tab and then come back to the tab with the grid, I notice that my Itemdatabound event is called twice and henece my total gets doubled up.
I can't figure out why the ItemdataBound event is fired twice.
<%@ Page Language="C#" MasterPageFile="~/enrollment/enrollmentWizard.master" AutoEventWireup="true" CodeFile="EDCP.aspx.cs" Inherits="enrollment_theCompany_EDCP" Title="M Benefit Solutions: The Comapny Enrollment" %><%@ MasterType VirtualPath="~/enrollment/enrollmentWizard.master" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><%@ Register TagPrefix="iSys" TagName="summary" Src="~/enrollment/ucEnrollmentSummary.ascx" %><%@ Register TagPrefix="iSys" TagName="fundBucket" Src="~/fund/ucFundbucket.ascx" %><%@ Register TagPrefix="iSys" TagName="deferralElections" Src="~/enrollment/thecompany/deferralElections.ascx" %><%@ Register TagPrefix="iSys" TagName="paymentOptions" Src="~/enrollment/thecompany/paymentOptions.ascx" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server"> <telerik:RadAjaxManagerProxy ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="rmpEnrollment"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rtsEnrollment" /> <telerik:AjaxUpdatedControl ControlID="rmpEnrollment" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="rtsEnrollment"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rtsEnrollment" /> <telerik:AjaxUpdatedControl ControlID="rmpEnrollment" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManagerProxy> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td> <telerik:RadTabStrip ID="rtsEnrollment" runat="server" MultiPageID="rmpEnrollment" OnTabClick="rtsEnrollment_TabClick" SelectedIndex="0" CausesValidation="true" Align="Justify" AutoPostBack="true"> </telerik:RadTabStrip> <telerik:RadMultiPage ID="rmpEnrollment" runat="server" SelectedIndex="0" OnPageViewCreated="rmpEnrollment_PageViewCreated" OnPreRender="rmpEnrollment_PreRender" RenderSelectedPageOnly="true" CssClass="multiPage"> </telerik:RadMultiPage> </td> </tr> </table></asp:Content>aspx.cspublic partial class enrollment_theCompany_EDCP : EnrollmentBasePage{ protected override void LoadStep() { string tabName = rtsEnrollment.SelectedTab.Text; RadTab tab = rtsEnrollment.FindTabByText(tabName); switch (rtsEnrollment.SelectedTab.Text) { case "Deferral Elections": break; case "Distribution Elections": break; case "Fund Allocations": RadPageView pvFundAllocations = (RadPageView)tab.PageView.FindControl("fundAllocations"); ucFundBucket ucFundAllocations = (ucFundBucket)pvFundAllocations.FindControl("ucFundAllocations"); ucFundAllocations.LoadPlan(); break; case "Enrollment Summary": // commit data break; } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { AddTab("Deferral Elections", true); RadPageView pageView = new RadPageView(); pageView.ID = "DeferralElections"; rmpEnrollment.PageViews.Add(pageView); AddTab("Distribution Elections", false); AddTab("Fund Allocations", false); AddTab("Enrollment Summary", false); LoadStep(); } } #region UI Events protected void rmpEnrollment_PreRender(object sender, EventArgs e) { LoadStep(); } protected void rmpEnrollment_PageViewCreated(object sender, RadMultiPageEventArgs e) { Control pageViewContents = new Control(); //code } protected void rtsEnrollment_TabClick(object sender, RadTabStripEventArgs e) { Page.Validate(rtsEnrollment.ValidationGroup); if (Page.IsValid) rtsEnrollment.ValidationGroup = e.Tab.Value; LoadStep(); } protected void PreviousButton_Click(object sender, EventArgs e) { } protected void ContinueButton_Click(object sender, EventArgs e) { } protected void FinishButton_Click(object sender, EventArgs e) { } #endregion}.ascx for Fund Allocations <%@ Control Language="c#" Inherits="iSys.fund.ucFundBucket" CodeFile="ucFundbucket.ascx.cs" %><%@ Register TagPrefix="iSys" TagName="pieChart" Src="~/Common/ucPieChart.ascx" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><table width="100%" cellspacing="0" cellpadding="0" border="0"> <telerik:RadAjaxManagerProxy ID="RadAJAXManagerProxy1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="rgFunds"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="_successfulPostMessage" /> <telerik:AjaxUpdatedControl ControlID="rgFunds" LoadingPanelID="RadAjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="_fundsPanel" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManagerProxy> <asp:PlaceHolder ID="_allocationPanel" runat="server"> <asp:PlaceHolder ID="_fundsPanel" runat="server" Visible="true"> <tr valign="top"> <td align="left" style="width: 50%" rowspan="2"> <telerik:RadGrid ID="rgFunds" runat="server" AllowSorting="False" EnableViewState="true" AllowPaging="false" GridLines="Both" AllowMultiRowEdit="true" OnPreRender="rgFunds_PreRender" OnItemDataBound="rgFunds_ItemDataBound" OnItemCreated="rgFunds_ItemCreated" OnItemCommand="rgFunds_ItemCommand" OnNeedDataSource="rgFunds_NeedDataSource"> <MasterTableView TableLayout="Fixed" HierarchyDefaultExpanded="true" CommandItemDisplay="Bottom" EditMode="InPlace" EnableNoRecordsTemplate="true"> <CommandItemTemplate> <table width="100%"> <tr> <td colspan="4" align="left"> <asp:CheckBox ID="chkAutoRebalance" runat="server" Visible="false" CssClass="checkbox" OnCheckedChanged="chkAutoRebalance_CheckedChanged" /> </td> <td align="right"> <asp:Button ID="btnPostTransaction" runat="server" Text="Post Transaction" CssClass="button" CommandName="PostTransaction" /> </td> </tr> </table> </CommandItemTemplate> <Columns> <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" FooterStyle-HorizontalAlign="Left" UniqueName="InvestmentOptions" ReadOnly="true" HeaderText="Investment Options"> <ItemTemplate> <asp:HyperLink ID="_pdfLink" runat="server" ImageUrl="~/App_Themes/Images/pdf_icon.gif" Visible="false" /> <asp:Label ID="_color" runat="server"> </asp:Label> <asp:Label ID="_fundName" runat="server" Text='<%# Eval("fundName")%>'></asp:Label> <asp:CheckBox ID="_excludeFund" runat="server" Checked='<%# Eval("allowRebalanceExclude")%>' Text="Exclude?" Visible='<%# Eval("allowRebalanceExclude")%>' /> <input type="hidden" id="_fundID" runat="server" /> <input type="hidden" id="_autoRebalanceFlag" runat="server" /> <input type="hidden" id="_allowRebalance" runat="server" /> </ItemTemplate> <FooterTemplate> <strong>Total must equal 100%</strong></FooterTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Right" HeaderText="Current %" HeaderStyle-Width="20%" ReadOnly="true" DataField="currentPercent" UniqueName="currentPercent"> <ItemTemplate> <asp:Label ID="_currentPercent" runat="server" Text='<%# Eval("currentPercent", "{0:N2}%")%>'> </asp:Label></ItemTemplate> <%--<FooterTemplate> <asp:Label ID="fundTotalOld" runat="server" />% </FooterTemplate>--%> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Right" UniqueName="futurePercent" HeaderStyle-Width="20%" HeaderText="New %"> <ItemTemplate> <asp:Label ID="_futurePercent" runat="server" Text='<%# Eval("futurePercent", "{0:N2}%")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtNewPercent" runat="server" CssClass="percent" groupName="allocations" Width="40px" onchange="SumGroup(this, false)" Text='<%# Eval("futurePercent")%>' /> % <asp:RangeValidator ID="newPercentageRange" runat="server" ControlToValidate="txtNewPercent" Type="Integer" CssClass="errormessagesmall" Display="None" /> <asp:CustomValidator ID="newPercentageIncrement" runat="server" ControlToValidate="txtNewPercent" ClientValidationFunction="Mod_ClientValidate" CssClass="errormessagesmall" Display="None" /> <cc1:ValidatorCalloutExtender ID="newPercentageRangeCallout" runat="server" TargetControlID="newPercentageRange" Width="235px" /> <cc1:ValidatorCalloutExtender ID="newPercentageIncrementCallout" runat="server" TargetControlID="newPercentageIncrement" Width="235px" /> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="fundTotal" runat="server" CssClass="percent" onfocus="blur()" Enabled="false" Font-Bold="true" ForeColor="Black" Width="40px" /> % <asp:CompareValidator ID="totalEqual100" runat="server" ControlToValidate="fundTotal" ValueToCompare="100" Operator="Equal" CssClass="errormessagesmall" Display="None" ErrorMessage="New allocations must total 100%." /> <asp:RequiredFieldValidator ID="fundTotalRequired" runat="server" ControlToValidate="fundTotal" Display="None" Visible="false" ErrorMessage="You <em>must</em> enter an allocation." /> <cc1:ValidatorCalloutExtender ID="fundTotalRequiredCallout" runat="server" TargetControlID="fundTotalRequired" Width="235px" /> <cc1:ValidatorCalloutExtender ID="totalEqual100Callout" runat="server" TargetControlID="totalEqual100" Width="235px" /> </FooterTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> </td> </tr> </asp:PlaceHolder></table>.ascx.cs public partial class ucFundBucket : userControl { public void LoadPlan() { rgFunds.Rebind(); } /// <summary> /// Loads the percents table and the charts /// </summary> private void DrawPie() { DateTime today = DateTime.Now; DataTable dt; DataView dv, dvFuture; if (_allocationType == FundAllocation.AllocationType.Rebalance) { //code } else { //code } // bind to grid rgFunds.DataSource = dt; } protected void rgFunds_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == "PostTransaction") { //code } } protected void rgFunds_PreRender(object source, EventArgs e) { // only visible if is the actual employee btnPostTransaction.Visible = (ShowPostTransactionButton && IsCurrentEmployee); //Puts the grid in editmode foreach (GridItem item in rgFunds.MasterTableView.Items) { if (item is GridEditableItem) { GridEditableItem editableItem = item as GridDataItem; editableItem.Edit = true; } } rgFunds.Rebind(); // Add the attribute to the fundTotal textbox GridItem gridFooterItem = rgFunds.MasterTableView.GetItems(GridItemType.Footer)[0]; TextBox fundTotal = (TextBox)gridFooterItem.FindControl("fundTotal"); GridItem[] gridEditItem = rgFunds.MasterTableView.GetItems(GridItemType.EditItem); if (gridEditItem.Count() > 0) { foreach (GridItem item in gridEditItem) { TextBox txtNewPercent = item.FindControl("txtNewPercent") as TextBox; txtNewPercent.Attributes.Add("totalName", fundTotal.ClientID); } } } protected void rgFunds_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { DrawPie(); } protected void rgFunds_ItemCreated(object sender, GridItemEventArgs e) { //code } protected void rgFunds_ItemDataBound(object source, GridItemEventArgs e) { if (e.Item is GridDataItem && e.Item.IsInEditMode) { GridDataItem item = (GridDataItem)e.Item; DataRowView view = (DataRowView)item.DataItem; //some code TextBox txtNewPercent = (TextBox)item["futurePercent"].FindControl("txtNewPercent"); string newPercent = txtNewPercent.Text.Replace("%", ""); _futureTotals += Double.Parse((newPercent == "") ? "0" : newPercent); } if (e.Item is GridFooterItem ) { GridFooterItem footerItem = (GridFooterItem)e.Item; TextBox fundTotal = (TextBox)footerItem["futurePercent"].FindControl("fundTotal"); fundTotal.Text = (_futureTotals > 0) ? _futureTotals.ToString() : ""; // require a future allocation if previous is zero RequiredFieldValidator fundTotalRequired = (RequiredFieldValidator)footerItem["futurePercent"].FindControl("fundTotalRequired"); fundTotalRequired.Visible = ((_allocationType == FundAllocation.AllocationType.Future) && (_currentTotals == 0)); } } }}