I have a page that has a RadDockLayout and the RadDocks are loaded dynamically in the OnInit event. The issue I'm having is that the OnInit event gets fired the same number of times as the number of RadDocks that are generated. So if I have 7 RadDocks, the OnInit gets fired 7 times. I only want that event to fire once. Please take a look at my code and let me know what I'm doing wrong. Thanks.
Test.apx.cs (some parameters have been removed for security purpose)
TestControl.ascx
TestControl.ascx.cs
Test.aspx
<telerik:RadAjaxPanel ID="ClientViewAjaxPanel" runat="server"> <telerik:RadScriptManager ID="ScriptManager1" runat="server"> </telerik:RadScriptManager> <div class="clientviewmaindiv"> <center> <asp:UpdatePanel runat="server" ID="UpdatePanel1" ChildrenAsTriggers="false" UpdateMode="Conditional"> <ContentTemplate> <telerik:RadDockLayout runat="server" ID="RadDockLayout1" EnableEmbeddedSkins="true" Skin="Office2007" Visible="true"> <div id="clientviewlayout" style="width:99%"> <table cellpadding="0" cellspacing="0" class="tblClientViewLayout" style="width:99%"> <tr> <td class="tdClientViewleftcol"> <telerik:RadDockZone MinHeight="200px" BorderStyle="None" BorderWidth="0" runat="server" ID="RadDockZoneV1" Orientation="Vertical"></telerik:RadDockZone> </td> <td class="tdClientViewrightcol"> <telerik:RadDockZone MinHeight="200px" BorderStyle="None" BorderWidth="0" runat="server" ID="RadDockZoneV3" Orientation="Vertical"></telerik:RadDockZone> </td> </tr> </table> </div> </telerik:RadDockLayout> </ContentTemplate> </asp:UpdatePanel> </center> </div> <telerik:RadWindowManager ID="RadWindowManager1" runat="server" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true" Modal="true" Skin="GIRadWindow" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins="false"> <Windows> <telerik:RadWindow runat="server" ID="NewsWindow" Width="600" Height="450" BackColor="White" Behaviors="Close,Move,Resize"></telerik:RadWindow> </Windows> </telerik:RadWindowManager> </telerik:RadAjaxPanel>Test.apx.cs (some parameters have been removed for security purpose)
protected override void OnInit(EventArgs e) { base.OnInit(e); UserContext = (Context)Session[""]; _ctx = new GBMDataContext(); int userChartsCount = 0; DataSet userCharts = new DataSet("userCharts"); using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[""].ConnectionString)) { SqlCommand command = new SqlCommand("", connection); command.CommandTimeout = 3000; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("", )); command.Parameters.Add(new SqlParameter("", )); command.Parameters.Add(new SqlParameter("", )); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = command; try { command.Connection.Open(); da.FillSchema(userCharts, SchemaType.Source); da.Fill(userCharts); } catch { userChartsCount = 0; } finally { command.Connection.Close(); } } userChartsCount = userCharts.Tables[0].Rows.Count; if (userChartsCount > 0) { RadDock dockWidget; Control ctrlWidget; double rowCount = 1; int widgetCount = 0; if (userChartsCount > 1) { rowCount = Math.Ceiling(Convert.ToDouble(userChartsCount) / 2); } for (int x = 0; x < rowCount; x++) { for (int y = 0; y <= 1; y++) { if (widgetCount < userChartsCount) { dockWidget = new RadDock(); dockWidget.ID = (string)(userCharts.Tables[0].Rows[widgetCount]["DockId"]) + widgetCount.ToString(); dockWidget.Tag = (string)(userCharts.Tables[0].Rows[widgetCount]["DockId"]) + widgetCount.ToString(); dockWidget.DockMode = DockMode.Docked; dockWidget.Skin = "Office2007"; dockWidget.Width = Unit.Pixel((int)userCharts.Tables[0].Rows[widgetCount]["DockWidth"]); dockWidget.DockHandle = DockHandle.TitleBar; dockWidget.DefaultCommands = Telerik.Web.UI.Dock.DefaultCommands.All; dockWidget.Title = _ctx.fn_GetTextLabelTranslationByLabelName((string)userCharts.Tables[0].Rows[widgetCount]["Name"], UserContext.Language_RecordID); ctrlWidget = LoadControl((string)userCharts.Tables[0].Rows[widgetCount]["ControlURL"]); ctrlWidget.ID = (string)userCharts.Tables[0].Rows[widgetCount]["ControlId"]; RadDockLayout1.Controls.Add(dockWidget); if (userCharts.Tables[0].Rows[widgetCount]["Zone"] == null) { if (y == 0) { RadDockZoneV1.Controls.Add(dockWidget); } else { RadDockZoneV3.Controls.Add(dockWidget); } } else { if ((int)userCharts.Tables[0].Rows[widgetCount]["Zone"] == 1) { RadDockZoneV1.Controls.Add(dockWidget); } else if ((int)userCharts.Tables[0].Rows[widgetCount]["Zone"] == 2) { RadDockZoneV3.Controls.Add(dockWidget); } } dockWidget.ContentContainer.Controls.Add(ctrlWidget); } widgetCount++; } } } }TestControl.ascx
<telerik:RadAjaxPanel ID="ClientViewControlRadAjaxPanel" runat="server"> <asp:Timer ID="ClientViewControlTimer" Interval="1" runat="server"></asp:Timer> <asp:MultiView ID="ClientViewControlMultiView" runat="server" ActiveViewIndex="0"> <asp:View ID="ClientViewControlLoadingView" runat="server" > <div id="loadingdiv" style="height:75px; margin-top:0px; margin-bottom:0px; padding:0px; background-repeat:no-repeat; background-position:center; background-image:url('../Skins/GIRadWindow/GIRadWindow/Window/loading.gif');"></div> </asp:View> <asp:View ID="ClientViewControlView" runat="server"> <asp:LinqDataSource ID="dsNews" runat="server" OnSelecting="dsNews_Selecting" /> <asp:ListView ID="lvNews" runat="server" DataKeyNames="RecordID" DataSourceID="dsNews"> <LayoutTemplate> <div id="itemPlaceholderContainer" runat="server"> <div id="itemplaceholder" runat="server"></div> </div> <div style="clear: left; text-align:center; vertical-align: middle; float:none; width:100%;"> <asp:DataPager ID="pageTopics" runat="server" PageSize="3" PagedControlID="lvNews"> <Fields> <asp:NextPreviousPagerField ButtonCssClass="pagerbuttons" ShowFirstPageButton="true" ButtonType="Image" ShowPreviousPageButton="false" ShowNextPageButton="false" FirstPageImageUrl="../Images/PagingFirst.gif" /> <asp:NextPreviousPagerField ButtonCssClass="pagerbuttons" ShowFirstPageButton="false" ButtonType="Image" ShowPreviousPageButton="true" ShowNextPageButton="false" PreviousPageImageUrl="../Images/PagingPrev.gif" /> <asp:NumericPagerField CurrentPageLabelCssClass="pagerbuttons" NumericButtonCssClass="pagerbuttons" ButtonCount="9" /> <asp:NextPreviousPagerField ButtonCssClass="pagerbuttons" ShowFirstPageButton="false" ButtonType="Image" ShowPreviousPageButton="false" ShowNextPageButton="true" ShowLastPageButton="false" NextPageImageUrl="../Images/PagingNext.gif" /> <asp:NextPreviousPagerField ButtonCssClass="pagerbuttons" ShowFirstPageButton="false" ButtonType="Image" ShowPreviousPageButton="false" ShowNextPageButton="false" ShowLastPageButton="true" LastPageImageUrl="../Images/PagingLast.gif" /> </Fields> </asp:DataPager> </div> </LayoutTemplate> <ItemTemplate> <div> <ul id="newsul"> <li id="newstitle"><asp:HyperLink runat="server" ID="titleNav" NavigateUrl='<%# Eval("OpenNewsURL")%>'><%# Eval("Name")%></asp:HyperLink> <li id="newspub"> <div style="width:100%;margin:0;padding:0;"> <div style="text-align:left;float:left;">Published: <%# Eval("PublishDate")%></div> <div style="text-align:right;"><asp:HyperLink runat="server" ID="newNav" ImageUrl="../Images/clientview/Globe.gif" NavigateUrl='<%# Eval("URL")%>' Target="_blank" /></div> </div> </li> <li id="newsdesc"><%# Eval("Description").ToString()%></li> </ul> </div> </ItemTemplate> <EmptyDataTemplate><div id="emptylist" class="emptylist">No news found</div></EmptyDataTemplate> </asp:ListView> </asp:View> </asp:MultiView> </telerik:RadAjaxPanel>TestControl.ascx.cs
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (IsPostBack) { ClientViewControlTimer.Enabled = false; if (ClientViewControlMultiView.ActiveViewIndex == 0) { ClientViewControlMultiView.SetActiveView(ClientViewControlView); } } } protected void dsNews_Selecting(object sender, LinqDataSourceSelectEventArgs args) { args.Result = LoadData(); } private IList LoadData() { UserContext = (Context)Session[""]; _userCulture = System.Globalization.CultureInfo.GetCultureInfo(UserContext.Locale); GBMDataContext ctx = new GBMDataContext(); var NewsProfiles = from tmp2 in ctx.ApplicationProfileNewsRoomIntersects where tmp2.ApplicationProfile_RecordID == UserContext.ApplicationProfile_RecordID select tmp2.NewsRoom_RecordID; var q = from tmp in ctx.NewsRooms where (!(tmp.RecordExpiration.HasValue) || tmp.RecordExpiration.Value >= DateTime.UtcNow) && tmp.LookupNewsCategory.Name != "Health and Benefits" && NewsProfiles.Contains(tmp.RecordID) && (tmp.Tenant_RecordID == UserContext.TenantId || tmp.Tenant_RecordID == null) orderby tmp.PublishDate descending select new { tmp.RecordID, Name = tmp.Name.Substring(0, 75), PublishDate = tmp.PublishDate.ToString("d", _userCulture), Description = tmp.Description != null ? tmp.Description.Substring(0, 175) : "", URL = tmp.URL, OpenNewsURL = "javascript:openNews('" + tmp.RecordID + "');" }; return q.ToList(); }