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

How can we add TabStrip in Custom Server control

2 Answers 28 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Sagar Baheti
Top achievements
Rank 1
Sagar Baheti asked on 23 Sep 2008, 06:45 AM
Hi ,
I am creating a custom server control and now i want to add Tabstrip into that, So could you please provide a sample application so that i can add TabStrip in Custom Server control

Thanks and rgard,
Sagar

2 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 25 Sep 2008, 01:36 PM
Hi Sagar,

Without knowing quite what functionality you are looking for it is hard to say what to put into the control, but here goes... :)

This the control file:

WebUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" SelectedIndex="0">  
    <Tabs> 
        <telerik:RadTab runat="server" Selected="True" Text="Root RadTab1">  
        </telerik:RadTab> 
        <telerik:RadTab runat="server" Text="Root RadTab2">  
        </telerik:RadTab> 
        <telerik:RadTab runat="server" Text="Root RadTab3">  
        </telerik:RadTab> 
        <telerik:RadTab runat="server" Text="Root RadTab4">  
        </telerik:RadTab> 
        <telerik:RadTab runat="server" Text="Root RadTab5">  
        </telerik:RadTab> 
    </Tabs> 
</telerik:RadTabStrip> 
 

And here is WebUserControl.ascx.cs:
using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Xml.Linq;  
 
public partial class WebUserControl : System.Web.UI.UserControl  
{  
 
    public int TabSelected  
    {  
        get { return RadTabStrip1.SelectedIndex; }  
        set { RadTabStrip1.SelectedIndex = value; }  
    }  
 
}  
 

This lets you get the selected index value of the RadTabStrip in the following aspx file... Sorry it is part of a master/content setup, I do all my testing in there!  The important things to note are registering the control at the top and how you add the control to the page.

Default6.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" Title="Untitled Page" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register Src="~/WebUserControl.ascx" TagName="MyControl" TagPrefix="myweb" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">  
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
<br /> 
 
    <myweb:MyControl ID="MyTabControl" runat="server" /> 
 
<br /><br /> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
<br /><br /> 
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
<br /> 
</asp:Content> 
 
 

And last but not least, when you click the button here is the code-behind that shows how you access the value from the control:

Default6.aspx.cs
using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Xml.Linq;  
 
public partial class Default6 : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {    }  
 
    protected void Button1_Click(object sender, EventArgs e)  
    {  
        Label1.Text = MyTabControl.TabSelected.ToString();  
    }  
}  
 

That's it in a nutshell. =D
0
pasquale
Top achievements
Rank 1
answered on 29 Oct 2008, 10:55 AM
Hi,
i've the same problem.. but i'm not speaking about "UserControl" but
"Custom Server control " so i don't have a UI and i've to create all the objects at run-time..
Any suggestions?
Tags
TabStrip
Asked by
Sagar Baheti
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
pasquale
Top achievements
Rank 1
Share this question
or