This is a migrated thread and some comments may be shown as answers.

How to close Tab dynamically

7 Answers 195 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
smith spd
Top achievements
Rank 1
smith spd asked on 21 Jun 2010, 07:41 PM
Hello Telerik Team,

I referred this blog and was able to load UserControls dynamically from code-behind.
Even this blog shows how to close the tabs.
But, I would like to know how can I close the tabs if I create and tabs dynamically from code-behind.
Please help with a working code to this.

MyCode:
 Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        If Not Page.IsPostBack Then 
            AddTab("Custom1")  
            AddTab("Custom2")  
        End If 
    End Sub 
    Private Sub AddTab(ByVal tabName As String)  
        Dim tab As New RadTab()  
        tab.Text = tabName  
        RadTabStrip1.Tabs.Add(tab)  
        Dim pageView As New RadPageView()  
        pageView.ID = tabName  
        RadMultiPage1.PageViews.Add(pageView)  
    End Sub 
 
    Protected Sub RadMultiPage1_PageViewCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadMultiPageEventArgs) Handles RadMultiPage1.PageViewCreated  
        Dim userControlName As String = e.PageView.ID + ".ascx" 
        Dim userControl As Control = Page.LoadControl(userControlName)  
        userControl.ID = e.PageView.ID + "_userControl" 
        e.PageView.Controls.Add(userControl)  
    End Sub 
aspx:
 <script type="text/javascript">  
       var tabStrip = $find("<%= RadTabStrip1.ClientID %>");  
       var multiPage = $find("<%= RadMultiPage1.ClientID %>");  
       var tab = tabStrip.findTabByText(tabText);  
       var pageView = tab.get_pageView();  
 
       var tabtabToSelect = tab.get_nextTab();  
       if (!tabToSelect)  
           tabtabToSelect = tab.get_previousTab();  
 
       tabStrip.get_tabs().remove(tab);  
       multiPage.get_pageViews().remove(pageView);  
 
       if (tabToSelect)  
           tabToSelect.set_selected(true);  
 
   </script> 
 
 <telerik:RadTabStrip Style="position: absolute; top: 84px;" ID="RadTabStrip1" SelectedIndex="0" 
                runat="server" MultiPageID="RadMultiPage1">  
                <TabTemplate> 
                      <%# DataBinder.Eval(Container, "Text") %> 
        <img style="margin-left: 10px" src="img/close.png" alt="delete" onclick="deleteTab('<%# DataBinder.Eval(Container, "Text") %>')" /> 
    </TabTemplate> 
 
            </telerik:RadTabStrip> 
            <telerik:RadMultiPage Style="position: absolute; top: 134px;" ID="RadMultiPage1" 
                runat="server" SelectedIndex="0">  
            </telerik:RadMultiPage> 
    </div> 

This doesn't work for tabs instantiated from code-behind.

Thanks

7 Answers, 1 is accepted

Sort by
0
smith spd
Top achievements
Rank 1
answered on 21 Jun 2010, 11:48 PM
Never mind.
This blog resolved my issue.
But I am stuck with a new issue of CSS. Can somebody post a simple css for TabStrip that would include ImageButton (close).
I have my aspx something like this :
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" Orientation="HorizontalTop" Skin="Telerik" Width="100%" SelectedIndex="0" Style="position: absolute;" MultiPageID="RadMultiPage1">  
        <TabTemplate> 
                    <asp:ImageButton ID="ImageButton1" runat="server" Height="10px" Width="10px" OnClick="ImageButton1_Click" ImageUrl="~//close.gif"/>  
            </TabTemplate> 
        </telerik:RadTabStrip> 
         <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" Height="100%" Width="100%" Style="position: relative;">                  
         </telerik:RadMultiPage> 
 
I get a wierd display which looks something like the attached file.
Mock
Top achievements
Rank 1
commented on 30 May 2021, 12:16 PM | edited

jbh
Mock
Top achievements
Rank 1
commented on 30 May 2021, 12:16 PM

oh whoops
0
JH
Top achievements
Rank 1
answered on 03 Aug 2010, 08:19 AM
I'm interested in this as well. Found any solution yet?
0
Yana
Telerik team
answered on 03 Aug 2010, 08:53 AM
Hello there,

Please check this online example  - it shows similar approach.

Best wishes,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
JH
Top achievements
Rank 1
answered on 03 Aug 2010, 09:54 AM
Thanks.
I found this example earlier. The difference is that I want to dynamically add the tab with the close button. Any ideas on how this can be done?
0
Yana
Telerik team
answered on 03 Aug 2010, 11:45 AM
Hello,

This help article explains how to add templates dynamically.

Greetings,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Hiren
Top achievements
Rank 1
answered on 01 Jun 2011, 01:42 PM
the link you given is not working, please update the link
for adding closebutton to template dynamically
0
Veronica
Telerik team
answered on 01 Jun 2011, 03:56 PM
Hello Giri,

We've made some changes to the links of the help articles recently so there may be some "Error" pages when you try to access them. We'll do our best to clear all those wrong urls. Here's the correct link:

http://www.telerik.com/help/aspnet-ajax/tabstrip-add-templates-runtime.html

Kind regards,
Veronica Milcheva
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
TabStrip
Asked by
smith spd
Top achievements
Rank 1
Answers by
smith spd
Top achievements
Rank 1
JH
Top achievements
Rank 1
Yana
Telerik team
Hiren
Top achievements
Rank 1
Veronica
Telerik team
Share this question
or