I have a requirements to implement a functionality which contains a panelbar, radtapstrip and the radmultipage. The panelbar items are added dynamically. when I clicked an item in the panelbar, a tabitem will be added (which contains a closetemplate to close a tab) along with the corresponding radmultipage item which loads a specific usercontrol. If the RadTabstrip text is existing it will activate the tab, when I click the close tab (image) the current tab should be deleted along with corresponsing multipage item and previous tab should be selected. The problem is when I try to close a particular tab, it focus on the previous tab but the content of the radmultipage item is still the current one that I've deleted.I want to activate the previous tab along with corresponding radmultipage item. What is the problems, any help please?
Inline Code
<%
@ Page Language="C#" AutoEventWireup="true" MasterPageFile="Site.Master" CodeBehind="default2.aspx.cs" Inherits="CapWorks.Web.default2" %>
<
asp:Content ID="ajaxscripts" runat="server" ContentPlaceHolderID="ajaxscripts">
</
asp:Content>
<
asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
</telerik:RadCodeBlock>
<
script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<
script type="text/javascript">
function ExportDocuments() {
var inputElements = document.getElementsByTagName("input");
var iElements = inputElements.length;
inputElements[
'<%= txtIds.ClientID %>'].value = "";
for (count = 0; count < iElements; count++) {
if (inputElements[count].type == 'checkbox') {
if (inputElements[count].checked) {
document.getElementById(
'<%= txtIds.ClientID %>').value += inputElements[count].id + ':';
}
}
}
var url = "./dialogues/common/selectoutput.aspx";
window.radopen(url,
"exportdocuments");
}
function removeTab(tabText) {
var tabStrip = $find("<%= topTabs.ClientID %>");
var multiPage = $find("<%= RadMultiPage1.ClientID %>");
var tab = tabStrip.findTabByText(tabText);
var pageView = tab.get_pageView();
var tabToSelect = tab.get_nextTab();
if (!tabToSelect)
tabToSelect = tab.get_previousTab();
tabStrip.get_tabs().remove(tab);
multiPage.get_pageViews().remove(pageView);
if (tabToSelect)
tabToSelect.set_selected(
true);
}
function OnClientItemClicking(sender, args) {
var multiPage = $find("<%=RadMultiPage1.ClientID%>");
var item = args.get_item();
var itemt = item.get_value();
if (multiPage.get_pageViews().get_count() > 0) {
if (multiPage.findPageViewByID(itemt)) {
var pageView = multiPage.findPageViewByID(itemt);
pageView.set_selected(
true);
pageView.show();
item.set_postBack(
false);
}
}
}
</
script>
</
asp:Content>
<
asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<
telerik:RadAjaxManager ID="DefaultAjaxManager" runat="server">
<
AjaxSettings>
<telerik:AjaxSetting AjaxControlID="leftPanel">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadMultiPage1" />
<telerik:AjaxUpdatedControl ControlID="topTabs" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</
telerik:RadAjaxManager>
<table style="padding-top:3px;padding-right:7px;">
<tr>
<td valign="top">
<telerik:RadPanelBar CssClass="panelbar" ID="leftPanel" runat="server" OnClientItemClicking="OnClientItemClicking"
AllowCollapseAllItems="True" OnItemClick="RadPanelBarItemClick"
Width="160px" ExpandMode="SingleExpandedItem">
<ExpandAnimation Type="InElastic" Duration="1"></ExpandAnimation>
<CollapseAnimation Type="InElastic" Duration="1"></CollapseAnimation>
</telerik:RadPanelBar>
</td>
<td valign="top">
<div style="float:left">
<input type="hidden" runat="server" ID="txtIds" />
<asp:HiddenField ID="markfornotify" Value="" runat="server" />
<
asp:HiddenField ID="selectedValues" Value="" runat="server" />
<
div id="tabsandpages">
<
telerik:RadTabStrip ID="topTabs" runat="server"
MultiPageID="RadMultiPage1" OnTemplateNeeded="TopTabsTemplateNeeded"
style="float:left">
</
telerik:RadTabStrip>
<
input id="hdnSelectedTab" type="hidden" value="none" runat="server" />
<
telerik:RadMultiPage ID="RadMultiPage1" Runat="server" style="padding-top:26px;" OnPreRender="RadPageMultiPageViewRender">
</
telerik:RadMultiPage>
</
div>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"
VisibleStatusbar="false" Behaviors="Close" Modal="true" Width="450px"
Height="430px" style="z-index:9999" >
<Localization Close ="<%$ Resources:CapWorksResource,close %>" Cancel="<%$ Resources:CapWorksResource,Cancel %>"
OK="<%$ Resources:CapWorksResource, ok %>" No="<%$ Resources:CapWorksResource, no %>" Yes="<%$ Resources:CapWorksResource, yes %>" />
<Windows>
<telerik:RadWindow ID="UserListDialog" runat="server" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" >
</telerik:RadWindow>
<telerik:RadWindow ID="UserListDialog1" runat="server" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" Width="700px" >
</telerik:RadWindow>
<telerik:RadWindow ID="editdocumentheadwindow" InitialBehaviors="Maximize" runat="server" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" Behaviors="Maximize,Close,Resize" >
</telerik:RadWindow>
<telerik:RadWindow runat="server" ID="exportdocuments" >
</telerik:RadWindow>
<telerik:RadWindow ID="findall" runat="server" ReloadOnShow="true"
ShowContentDuringLoad="false" Modal="true" AutoSize="true" Behaviors="Move,Resize,Close">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
</div>
</td>
</tr>
</table>
</
asp:Content>
 
 
Code -Behind
using
System;
using
System.Globalization;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
CapWorks.Web.Helpers.RadPanelManager;
using
CapWorks.Web.UserControls;
using
Telerik.Web.UI;
namespace
CapWorks.Web
{
public partial class default2 : PageBase
{
private const string UserControls = "/UserControls/";
private const string ExtensionId = "_userControl";
private void AddCloseButton(Control tab)
{
var template = new CloseTabTemplate();
template.InstantiateIn(tab);
template.Closed += TemplateClosed;
}
private void AddTab(string key,string tabName,string controlname, bool isselected)
{
var tab = new RadTab { Text = tabName, Selected = isselected };
var pageView = new RadPageView {ID = string.Format("{0}{1}{2}",key,Constants.GLOBAL_FOLDER_DELIMITER, controlname), Selected = isselected};
tab.PageViewID = pageView.ID;
topTabs.Tabs.Add(tab);
RadMultiPage1.PageViews.Add(pageView);
}
private void TemplateClosed(object sender, ImageClickEventArgs e)
{
var img = (ImageButton)sender;
var tabfind = topTabs.FindTabByText(img.ID.Replace("closeimg",""));
if (tabfind.Equals(null)) return;
topTabs.Tabs.Remove(tabfind);
var pageViewFind = topTabs.MultiPage.FindPageViewByID(tabfind.PageViewID);
if (pageViewFind.Equals(null)) return;
RadMultiPage1.PageViews.Remove(pageViewFind);
//if (topTabs.Tabs.Count <= 0) return;
//topTabs.Tabs[topTabs.Tabs.Count - 1].Selected = true;
//RadMultiPage1.PageViews[RadMultiPage1.PageViews.Count - 1].Selected = true;
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
LoadFirstMenu(leftPanel);
LoadOtherMenu(leftPanel);
var welcome = Resources.CapWorksResource.Welcome;
var culture = CultureInfo.CurrentUICulture;
AddTab(
"welcome",Localize("Welcome"),"welcome", false);
AddTab(
"butMy",Localize("Inbox"),"alldocs", true);
return;
}
}
protected void RadPanelBarItemClick(object sender, RadPanelBarEventArgs e)
{
if (e.Item.Value.Length == 0) return;
var itemlocal = Localize(e.Item.Text);
var attributekey = e.Item.Attributes[e.Item.Text];
var tabFound = topTabs.Tabs.FindTabByText(attributekey);
if (tabFound==null)
{
AddTab(attributekey, itemlocal, e.Item.Value,
true);
}
else
{
tabFound.Selected =
true;
tabFound.PageView.Selected =
true;
}
}
protected void RadPageMultiPageViewRender(object sender, EventArgs e)
{
foreach (RadPageView pageview in RadMultiPage1.PageViews){
var control = pageview.ID.Split(new string[] { Constants.GLOBAL_FOLDER_DELIMITER }, StringSplitOptions.None);
var isPageViewFound = RadMultiPage1.FindControl(pageview.ID);
if (isPageViewFound == null) return;
var userControlName = string.Format("{0}{1}.ascx", UserControls, control[1]);
var userControl = (ControlBase)Page.LoadControl(userControlName);
userControl.DataItem = control[0];
userControl.ID =
String.Format("{0}{1}", control[0], ExtensionId);
pageview.Controls.Add(userControl);
}
if (topTabs.Tabs.Count <= 0) return;
topTabs.Tabs[topTabs.Tabs.Count - 1].Selected =
true;
topTabs.Tabs[topTabs.Tabs.Count - 1].PageView.Selected = true;
}
protected void TopTabsTemplateNeeded(object sender, RadTabStripEventArgs e)
{
if (!e.Tab.Text.ToLower().Equals(Localize("welcome").ToLower()))
AddCloseButton(e.Tab);
}
}
}