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

add close button on tab

8 Answers 460 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Johnny
Top achievements
Rank 2
Johnny asked on 21 Dec 2011, 04:32 AM
hi i want to add close button on the tab if user click the close button n close the hide the tab how to achive this

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Dec 2011, 06:59 AM
Hello,

Take a look into the following demo.
TabStrip / Templates

Thanks,
Princy.
0
Kevin
Top achievements
Rank 1
answered on 02 Feb 2012, 07:08 PM
Hello,

This is exactly what I was looking for except I'm having a problem. My tab names are not showing up.

They are added server side in the on load event.  All I see is a blank tab with the "X" close button.  Any idea how to have the tab names show up?

protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AddTab("Customers");
                AddPageView(RadTabStrip1.FindTabByText("Customers"));
                AddTab("Orders");
                AddTab("Products");
            }
        }

Thanks!
Kevin
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2012, 07:29 AM
Hello,

Try the following code snippet.
C#:
protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack)
     {
      RadTab tab = new RadTab();
      tab.Text = "tab";
      tab.ImageUrl = "~/Images/button_edit_grey.gif";
      RadTabStrip1.Tabs.Add(tab);
     }
  }

Thanks,
princy.
0
Bozhidar
Telerik team
answered on 03 Feb 2012, 09:03 AM
Hi Kevin,

When you use templates you have to call the DataBind() method of RadTabStrip on each Page_Load event in order for the binding expressions to work and show the text.
 
Greetings,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Johnny
Top achievements
Rank 2
answered on 20 Feb 2012, 04:23 AM
hi i don't want to show close button for all tab
i need to hide the close button for First tab how to acive this?

and

i remove the tab and related pageview from client side
how do i add it back from client side
i add it back from client side using following code but the template doesn't show
am i missing something
var tabStrip = $find("ctl00_ContentPlaceHolder1_PageTab");
var multiPage = $find("ctl00_ContentPlaceHolder1_MultiPage");         
 
var tab = tabStrip.findTabByText("Search");
var pageView = tab.get_pageView();       
 
 tabStrip.get_tabs().add(tab);
 multiPage.get_pageViews().add(pageView);

0
Bozhidar
Telerik team
answered on 20 Feb 2012, 11:54 AM
Hello Johnny,

To answer your first question, aside from the global template that you set on RadTabStrip, you can also assign templates to tabs individually, overriding the global template for that tab. Using the TabStrip from the demo mentioned earlier, here's how you can set the first node so that it doesn't have the delete button:
<telerik:RadTabStrip runat="server" ID="RadTabStrip1" Orientation="HorizontalTop"
    Skin="WebBlue" SelectedIndex="0" MultiPageID="RadMultiPage1">
    <TabTemplate>
        <div class="textWrapper">
            <%# DataBinder.Eval(Container, "Text") %>
        </div>
        <span class="ie6shim"></span>
        <img src="delete.gif" alt="delete" onclick="deleteTab('<%# DataBinder.Eval(Container, "Text") %>')" />
    </TabTemplate>
    <Tabs>
        <telerik:RadTab Text="Products">
            <TabTemplate>
                <div class="textWrapper">
                    <%# DataBinder.Eval(Container, "Text") %>
                </div>
                <span class="ie6shim"></span>
            </TabTemplate>
        </telerik:RadTab>
        <telerik:RadTab Text="Services">
        </telerik:RadTab>
        <telerik:RadTab Text="Corporate">
        </telerik:RadTab>
    </Tabs>
</telerik:RadTabStrip>

And when you add new tabs, you always have to call the DataBind() method from the server, otherwise the databinding expressions wouldn't work. For this purpose you can use RadAjaxManager to make a partial postback and rebind the TabStrip whenever you add a new tab.
 
Kind regards,
Bozhidar
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Johnny
Top achievements
Rank 2
answered on 21 Feb 2012, 03:03 AM
hi Bozhidar

i don't want page postback on tab closingso i decided to hide 2nd and 3rd tab while page loading
In the AjaxLoadingPanel RequestEnd event i check the Hidden Variable Value then show or Hide the 2nd and 3rd Tab
my problem is when i close the 2nd tab by clicking close btn and select First tab by client side tab.set_selected(true); the fisrt tab
doesn't selected how to achive this
Page_Load Code
var tabStrip = $find("ctl00_ContentPlaceHolder1_PageTab");
  var multiPage = $find("ctl00_ContentPlaceHolder1_MultiPage");
 
  var tab = tabStrip.findTabByText("Search");
  var pageView = tab.get_pageView();
  tab.set_visible(false);
  pageView.hide();
  //        tabStrip.get_tabs().remove(tab);
  //        multiPage.get_pageViews().remove(pageView);
 
  tab = tabStrip.findTabByText("Viewer");
  pageView = tab.get_pageView();
  //        tabStrip.get_tabs().remove(tab);
  //        multiPage.get_pageViews().remove(pageView);
  tab.hide();
  pageView.hide();

AjaxLoading Panel OnRequestEnd event code
var tabStrip = $find("ctl00_ContentPlaceHolder1_PageTab");
        var multiPage = $find("ctl00_ContentPlaceHolder1_MultiPage");
 
        tabStrip.trackChanges();
 
        var tab = tabStrip.findTabByText("Search");
        var pageView = tab.get_pageView();
         
 
        if ($("#ContentPlaceHolder1_ResultTabVisibleHidden").attr("value") == "1") {
//            tabStrip.get_tabs().add(tab);
            //            multiPage.get_pageViews().add(pageView);
            tab.set_visible(true);
            pageView.show();
        }
        else {
//            tabStrip.get_tabs().remove(tab);
            //            multiPage.get_pageViews().remove(pageView);
            tab.set_visible(false);
            pageView.hide();
        }
 
        var tab = tabStrip.findTabByText("Viewer");
        var pageView = tab.get_pageView();
        if ($("#ContentPlaceHolder1_ViewerTabVisibleHidden").attr("value") == "1") {
//            tabStrip.get_tabs().add(tab);
            //            multiPage.get_pageViews().add(pageView);
            tab.show();
            pageView.show();
 
        }
        else {
//            tabStrip.get_tabs().remove(tab);
            //            multiPage.get_pageViews().remove(pageView);
            tab.hide();
            pageView.hide();
        }
 
        tabStrip.commitChanges();
This is my coseTab Code
function CloseTab(tabText) {
 
    
      var tabStrip = $find("ctl00_ContentPlaceHolder1_PageTab");
      var multiPage = $find("ctl00_ContentPlaceHolder1_MultiPage");
      var tab = tabStrip.findTabByText(tabText);
      var pageView = tab.get_pageView();
 
      var tabToSelect = tabStrip.findTabByText("Mail");
 
      tab.set_visible(false);
      pageView.hide();
 
         
 
      if (tabText == "Search") {
          $("#ContentPlaceHolder1_ResultTabVisibleHidden").attr("value", "0");
           
      }
      else if (tabText == "Viewer") {
          $("#ContentPlaceHolder1_ViewerTabVisibleHidden").attr("value", "0");
      }
 
      if (tabToSelect)
          tabToSelect.set_selected(true);
 
 
  }



0
Johnny
Top achievements
Rank 2
answered on 21 Feb 2012, 03:28 AM
i achived by adding 2 extra lines in CloseTab event

function CloseTab(tabText) {
 
     
       var tabStrip = $find("ctl00_ContentPlaceHolder1_PageTab");
       var multiPage = $find("ctl00_ContentPlaceHolder1_MultiPage");
       var tab = tabStrip.findTabByText(tabText);
       var pageView = tab.get_pageView();
 
       var tabToSelect = tabStrip.findTabByText("Mail");
 
       tab.set_visible(false);
       pageView.hide();
 
       tab.unselect();
       tab.disable();
 
       if (tabText == "Search") {
           $("#ContentPlaceHolder1_ResultTabVisibleHidden").attr("value", "0");
            
       }
       else if (tabText == "Viewer") {
           $("#ContentPlaceHolder1_ViewerTabVisibleHidden").attr("value", "0");
       }
 
       if (tabToSelect)
           tabToSelect.set_selected(true);
 
 
   }
Tags
TabStrip
Asked by
Johnny
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Bozhidar
Telerik team
Johnny
Top achievements
Rank 2
Share this question
or