Imports Telerik.Web.UI

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            AddTab("Domestic", "Domestic")
            AddTab("Air", "International Air")


            AddPageView(rtsMain.Tabs(0))
            rtsMain.SelectedIndex = 0
            rtsMain.Tabs(0).PageView.Selected = True
        End If

    End Sub

    Private Sub AddTab(ByVal tabName As String, ByVal TabText As String)
        Dim tab As New RadTab()
        tab.Text = TabText
        tab.Value = tabName
        rtsMain.Tabs.Add(tab)
    End Sub

    Protected Sub rtsMain_TabClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTabStripEventArgs) Handles rtsMain.TabClick
        AddPageView(e.Tab)
        e.Tab.PageView.Selected = True
    End Sub

    Private Sub AddPageView(ByVal tab As RadTab)
        Dim pageView As RadPageView = New RadPageView
        pageView.ID = tab.Value
        If IsNothing(rmpMain.FindPageViewByID(tab.Value)) Then
            rmpMain.PageViews.Add(pageView)
        End If
        tab.PageViewID = pageView.ID
    End Sub


    Protected Sub rmpMain_PageViewCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMultiPageEventArgs) Handles rmpMain.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

End Class
