So this is really simple. I want to load the same ascx 'x' number of times. And based on the Session Information, load the page a certain way. And I have that functionality working perfectly.
However, what happens is while clicking on the tabs. The radpageviews will no longer load, or be stuck on a previous page. Also, I noticed sometimes when the page renders the multipage it's a child of an already existing multipage.
Below is code for the entire project. Any help or a way to work with this idea would be fantastic. Thanks.
All the code I got to load the dynamic pages comes from the online demo. Thanks!
default.aspx
default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["RSession"] = new RSession.UserSession();
RadTabStrip_Populating();
}
}
protected void RadTabStrip_Populating()
{
string[] tabValues = { "String|A M A|ApplePumpkinButter|MyChoices", "Decimal|Base Happy Go Lucky turtle|BaseHappyGoLuckyturtle|MyHappyFunDay", "Decimal|Base Mountain Slopes|BaseMountainSlopes|MyFunWithTabs", "Decimal|Base Ski Slopes|BaseSkiSlopes|MyFunWithTabs", "Decimal|BaseSkiSlopeAdjustedHight|BaseSkiSlopeAdjustedHight|MoreFunWithTabs" };
foreach (string tv in tabValues)
{
RadTab RT = new RadTab();
RT.Text = tv.Split('|')[1];
RT.Value = tv;
RT.Width = Unit.Pixel(300);
RadTabStrip1.Tabs.Add(RT);
}
}
protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)
{
string userControlName = "dynamicbuilder.ascx";
Control userControl = Page.LoadControl(userControlName);
userControl.ID = e.PageView.ID.Replace(" ", "").Replace("|", "") + "_userControl";
e.PageView.Controls.Add(userControl);
}
private void AddPageView(RadTab tab)
{
RadPageView pageView = new RadPageView();
pageView.ID = tab.Text.Replace(" ", "");
RadMultiPage1.PageViews.Add(pageView);
tab.PageViewID = pageView.ID;
}
protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)
{
((RSession.UserSession)Session["RSession"]).CurrentParameterDT = e.Tab.Value.ToString().Split('|')[0].ToString();
((RSession.UserSession)Session["RSession"]).CurrentParameterFLH = e.Tab.Value.ToString().Split('|')[1].ToString();
((RSession.UserSession)Session["RSession"]).CurrentParameterFName = e.Tab.Value.ToString().Split('|')[2].ToString();
((RSession.UserSession)Session["RSession"]).CurrentParameterTName = e.Tab.Value.ToString().Split('|')[3].ToString();
AddPageView(e.Tab);
e.Tab.PageView.Selected = true;
}
}
dynamicbuilder.ascx
dynamicbuilder.ascx.cs
SessionControl.cs
However, what happens is while clicking on the tabs. The radpageviews will no longer load, or be stuck on a previous page. Also, I noticed sometimes when the page renders the multipage it's a child of an already existing multipage.
Below is code for the entire project. Any help or a way to work with this idea would be fantastic. Thanks.
All the code I got to load the dynamic pages comes from the online demo. Thanks!
default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %><!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> <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" /></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> <Scripts> <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> <script type="text/javascript"> function onTabSelecting(sender, args) { if (args.get_tab().get_pageViewID()) { args.get_tab().set_postBack(false); } } </script> <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1" Skin="MetroTouch"> </telerik:RadAjaxLoadingPanel> <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" EnablePageHeadUpdate="true"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadTabStrip1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadTabStrip1"></telerik:AjaxUpdatedControl> <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1"> </telerik:AjaxUpdatedControl> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadMultiPage1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadMultiPage1"></telerik:AjaxUpdatedControl> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage1" Skin="MetroTouch" Align="Justify" Orientation="VerticalLeft" OnTabClick="RadTabStrip1_TabClick" Width="1000" OnClientTabSelecting="onTabSelecting"> </telerik:RadTabStrip> <telerik:RadMultiPage ID="RadMultiPage1" runat="server" OnPageViewCreated="RadMultiPage1_PageViewCreated"> </telerik:RadMultiPage> <div> </div> </form></body></html>default.aspx.cs
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["RSession"] = new RSession.UserSession();
RadTabStrip_Populating();
}
}
protected void RadTabStrip_Populating()
{
string[] tabValues = { "String|A M A|ApplePumpkinButter|MyChoices", "Decimal|Base Happy Go Lucky turtle|BaseHappyGoLuckyturtle|MyHappyFunDay", "Decimal|Base Mountain Slopes|BaseMountainSlopes|MyFunWithTabs", "Decimal|Base Ski Slopes|BaseSkiSlopes|MyFunWithTabs", "Decimal|BaseSkiSlopeAdjustedHight|BaseSkiSlopeAdjustedHight|MoreFunWithTabs" };
foreach (string tv in tabValues)
{
RadTab RT = new RadTab();
RT.Text = tv.Split('|')[1];
RT.Value = tv;
RT.Width = Unit.Pixel(300);
RadTabStrip1.Tabs.Add(RT);
}
}
protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)
{
string userControlName = "dynamicbuilder.ascx";
Control userControl = Page.LoadControl(userControlName);
userControl.ID = e.PageView.ID.Replace(" ", "").Replace("|", "") + "_userControl";
e.PageView.Controls.Add(userControl);
}
private void AddPageView(RadTab tab)
{
RadPageView pageView = new RadPageView();
pageView.ID = tab.Text.Replace(" ", "");
RadMultiPage1.PageViews.Add(pageView);
tab.PageViewID = pageView.ID;
}
protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)
{
((RSession.UserSession)Session["RSession"]).CurrentParameterDT = e.Tab.Value.ToString().Split('|')[0].ToString();
((RSession.UserSession)Session["RSession"]).CurrentParameterFLH = e.Tab.Value.ToString().Split('|')[1].ToString();
((RSession.UserSession)Session["RSession"]).CurrentParameterFName = e.Tab.Value.ToString().Split('|')[2].ToString();
((RSession.UserSession)Session["RSession"]).CurrentParameterTName = e.Tab.Value.ToString().Split('|')[3].ToString();
AddPageView(e.Tab);
e.Tab.PageView.Selected = true;
}
}
dynamicbuilder.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="dynamicbuilder.ascx.cs" Inherits="dynamicbuilder" %><asp:Panel ID="Panel_Dec" runat="server" Visible="false"> <div style="padding-top: 10px;"> <div style="float: left; padding-left: 15px;"> <asp:Label runat="server" ID="Label_NumericStartingValue"></asp:Label> </div> <br /> <div style="padding-top: 10px;"> <div style="float: left; padding-left: 15px;"> <asp:Label runat="server" ID="Label_NumericEndingValue"></asp:Label> </div></asp:Panel><asp:Panel ID="Panel_NV" runat="server" Visible="false"> <asp:Label runat="server" ID="Label2" Text="nvarchar"></asp:Label></asp:Panel><asp:Panel ID="Panel_DT" runat="server" Visible="false"> <div style="padding-top: 10px;"> <div style="float: left; padding-left: 15px;"> <asp:Label runat="server" ID="Label_StartDate"></asp:Label> </div> <br /> <br /> <div style="float: left; padding-left: 15px;"> <asp:Label runat="server" ID="Label_EndDate"></asp:Label> </div> </div></asp:Panel><asp:Panel ID="Panel_SP" runat="server" Visible="false"> <asp:Label runat="server" ID="Label4" Text="Special"></asp:Label></asp:Panel>dynamicbuilder.ascx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class dynamicbuilder : System.Web.UI.UserControl{ protected void Page_Load(object sender, EventArgs e) { HidePanels(); string casestatement = ((RSession.UserSession)Session["RSession"]).CurrentParameterDT.ToLower(); switch (casestatement) { case ("string"): if (SpecialFields.Contains(((RSession.UserSession)Session["RSession"]).CurrentParameterFName.ToLower())) { Process_Special(); } else { Process_NVarChar(); } break; case ("integer"): Process_Decimal(); break; case ("decimal"): Process_Decimal(); break; case ("datetime"): Process_DateTime(); break; } } protected void HidePanels() { string casestatement = ((RSession.UserSession)Session["RSession"]).CurrentParameterDT.ToLower(); switch (casestatement) { case ("string"): if (SpecialFields.Contains(((RSession.UserSession)Session["RSession"]).CurrentParameterFName.ToLower())) { Panel_NV.Visible = false; Panel_DT.Visible = false; Panel_Dec.Visible = false; Panel_SP.Visible = true; } else { Panel_NV.Visible = true; Panel_DT.Visible = false; Panel_Dec.Visible = false; Panel_SP.Visible = false; } break; case ("integer"): Panel_NV.Visible = false; Panel_DT.Visible = false; Panel_Dec.Visible = true; Panel_SP.Visible = false; break; case ("decimal"): Panel_NV.Visible = false; Panel_DT.Visible = false; Panel_Dec.Visible = true; Panel_SP.Visible = false; break; case ("datetime"): Panel_NV.Visible = false; Panel_DT.Visible = true; Panel_Dec.Visible = false; Panel_SP.Visible = false; break; } } protected void Process_NVarChar() { } protected void Process_DateTime() { Label_StartDate.Text = ((RSession.UserSession)Session["RSession"]).CurrentParameterFLH + ": Starting Date"; Label_EndDate.Text = ((RSession.UserSession)Session["RSession"]).CurrentParameterFLH + ": Ending Date"; } protected void Process_Decimal() { Label_NumericStartingValue.Text = ((RSession.UserSession)Session["RSession"]).CurrentParameterFLH + ": Starting Value"; Label_NumericEndingValue.Text = ((RSession.UserSession)Session["RSession"]).CurrentParameterFLH + ": Ending Value"; } protected void Process_Special() { } protected string[] SpecialFields = { "mn", "ve" };}SessionControl.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;public static class RSession{ public class UserSession { public string CurrentParameterTName { get; set; } public string CurrentParameterFName { get; set; } public string CurrentParameterFLH { get; set; } public string CurrentParameterDT { get; set; } }}