How can we add TabStrip in Custom Server control

3 posts, 0 answers
  1. Sagar Baheti
    Sagar Baheti avatar
    28 posts
    Member since:
    May 2008

    Posted 23 Sep 2008 Link to this post

    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. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 25 Sep 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. pasquale
    pasquale avatar
    3 posts
    Member since:
    Oct 2008

    Posted 29 Oct 2008 Link to this post

    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?
Back to Top