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

How I can load the first UserControl for the first time the page appears

5 Answers 277 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Sami Aljafar
Top achievements
Rank 1
Sami Aljafar asked on 15 Feb 2009, 09:25 PM

Dear Telerik Team,

I'm new to the RadTabStrip and I'm trying to use it by the on demand approach.

I did follow some of the example in your web site and I'm using UserControl to display deferent content.

 

How I can load and show the first UserControl for the first time the page appears. Because my current situation is I have to click one tab first in order to load the related UserControl.


Thanks.

Code Behind File:
    Dim IsNewPageView As Boolean = False
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.Page.IsPostBack Then
            ViewState("sequence") = 0
        End If
    End Sub

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

    Private Function AddPageView(ByVal PageViewID As String) As String
        Dim PageView As RadPageView = New RadPageView
        PageView.ID = PageViewID
        IsNewPageView = True
        Me.RadMultiPage1.PageViews.Add(PageView)
        Me.RadMultiPage1.SelectedIndex = Me.RadMultiPage1.PageViews.Count - 1
        Return PageViewID
    End Function

 

    Protected Sub RadMultiPage1_PageViewCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMultiPageEventArgs) Handles RadMultiPage1.PageViewCreated
        Dim Sequence As Integer = 0
        If IsNewPageView Then
            Sequence = Convert.ToInt32(ViewState("sequence")) + 1
            ViewState("sequence") = Convert.ToString(Sequence)
        Else
            Sequence = e.PageView.MultiPage.PageViews.Count
        End If

        Select Case e.PageView.ID.Trim.ToUpper
            Case "Permanent".ToUpper
                Dim userControlName As String = "Permnent.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_Permnent"
                e.PageView.Controls.Add(userControl)
            Case "Standby".ToUpper
                Dim userControlName As String = "Standby.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_Standby"
                e.PageView.Controls.Add(userControl)
        End Select
    End Sub

ASPX File (Java Script:)
<script type="text/javascript">
    function onTabSelecting(sender, args)
    {
        if (args.get_tab().get_pageView())
        {
            if (args.get_tab().get_pageView().get_id())
            {
                args.get_tab().set_postBack(false);
            }
        }
    }             
</script>

5 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 16 Feb 2009, 09:27 AM
Hi Sami,

I think you've missed to review our Load On Demand RadPageView example. In addition, all Telerik examples are available offline with your installation of RadControls; by default, this particular example is located under C:\Program Files\Telerik\RadControls for ASPNET AJAX Q3 2008\Live Demos\TabStrip\Examples\ApplicationScenarios\LoadOnDemand on your machine.
All the best,
Paul
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sami Aljafar
Top achievements
Rank 1
answered on 16 Feb 2009, 05:11 PM

Hello Paul,

No I didn't miss the example I did review it and also I did watched the Telerik trainer video about the RadTabStrip. My first posted in this thread is a result of following what I learn from the trainer video and it works fine with me except loading the first UserControl for the first tab when the page appears for the first time.

Now I reviewed the Load On Demand RadPageView again and I compare it with what I did in my application. I couldn't load the first UserControl and also the UserControl doesn't load up when I click on the first tab for the first time so I have to click on any other tab then click back again on the first Tab to show it up.

Please why is that? what I'm missing here?

Thanks.

This is my actual Code behind File:

Dim IsNewPageView As Boolean = False

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
     

 

        If Not Me.Page.IsPostBack Then
            ViewState("sequence") = 0

            RadTabStrip1.FindTabByText("Permanent")          
        End If

End Sub

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

    Protected Sub RadMultiPage1_PageViewCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMultiPageEventArgs) Handles RadMultiPage1.PageViewCreated

        Dim Sequence As Integer = 0

        If IsNewPageView Then
            Sequence = Convert.ToInt32(ViewState("sequence")) + 1
            ViewState("sequence") = Convert.ToString(Sequence)
        Else
            Sequence = e.PageView.MultiPage.PageViews.Count
        End If

        Select Case e.PageView.ID.Trim.ToUpper
            Case "Permanent".ToUpper
                Dim userControlName As String = "Permnent.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_Permnent"
                e.PageView.Controls.Add(userControl)
            Case "Standby".ToUpper
                Dim userControlName As String = "Standby.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_Standby"
                e.PageView.Controls.Add(userControl)
            Case "Patient".ToUpper
                Dim userControlName As String = "PatientApps.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_PatientApps"
                e.PageView.Controls.Add(userControl)
            Case "Unconfirm".ToUpper
                Dim userControlName As String = "UnconfirmApps.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_UnconfirmApps"
                e.PageView.Controls.Add(userControl)
            Case "Physician".ToUpper
                Dim userControlName As String = "PhysicianApps.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_PhysicianApps"
                e.PageView.Controls.Add(userControl)
            Case "Room".ToUpper
                Dim userControlName As String = "RoomApps.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_RoomApps"
                e.PageView.Controls.Add(userControl)
            Case "Today".ToUpper
                Dim userControlName As String = "TodayApps.ascx"
                Dim userControl As Control = Page.LoadControl(userControlName)
                userControl.ID = e.PageView.ID & "_TodayApps"
                e.PageView.Controls.Add(userControl)
        End Select
End Sub

Private Function AddPageView(ByVal PageViewID As String) As String
        Dim PageView As RadPageView = New RadPageView
        PageView.ID = PageViewID
        IsNewPageView = True
        Me.RadMultiPage1.PageViews.Add(PageView)
        Me.RadMultiPage1.SelectedIndex = Me.RadMultiPage1.PageViews.Count - 1
        Return PageViewID
End Function

This is my actual ASPX File:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Masters/InternalPage.Master" CodeBehind="Appointments.aspx.vb" Inherits="JUVA.Appointments" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
    function onTabSelecting(sender, args)
    {
        if (args.get_tab().get_pageViewID())
        {
            args.get_tab().set_postBack(false);
        }
    }
</script>

<table cellpadding="0" border="0" cellspacing="0" width="900" bgcolor="#67A077">
 <tr>
   <td align="left">
       <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1">
            <asp:Image runat="server" ID="LoadingImage1" ImageUrl="~/Images/loading7.gif" AlternateText="Loading..." />
       </telerik:RadAjaxLoadingPanel>
       <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
           <AjaxSettings>
               <telerik:AjaxSetting AjaxControlID="RadTabStrip1">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                       <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
               <telerik:AjaxSetting AjaxControlID="RadMultiPage1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
           </AjaxSettings>
       </telerik:RadAjaxManager>
     </td>
 </tr>
 <tr>
   <td align="left"></td>
 </tr>
 <tr>
   <td align="left">
       <telerik:RadTabStrip ID="RadTabStrip1" runat="server" Skin="Forest"
           MultiPageID="RadMultiPage1" onclienttabselected="onTabSelecting"
           SelectedIndex="0">
           <Tabs>
               <telerik:RadTab runat="server" TabIndex="1" Text="Permanent"
                Selected="True" SelectedIndex="1" >
               </telerik:RadTab>
               <telerik:RadTab runat="server" TabIndex="2" Text="Standby">
               </telerik:RadTab>
               <telerik:RadTab runat="server" TabIndex="3" Text="Patient">
               </telerik:RadTab>
               <telerik:RadTab runat="server" TabIndex="4" Text="Unconfirm">
               </telerik:RadTab>
               <telerik:RadTab runat="server" TabIndex="5" Text="Physician">
               </telerik:RadTab>
               <telerik:RadTab runat="server" TabIndex="6" Text="Room">
               </telerik:RadTab>
               <telerik:RadTab runat="server" TabIndex="7" Text="Today">
               </telerik:RadTab>
           </Tabs>
       </telerik:RadTabStrip>
     </td>
 </tr>
 <tr>
   <td align="left">
       <telerik:RadMultiPage ID="RadMultiPage1"
         Runat="server" SelectedIndex="0"
         OnPageViewCreated="RadMultiPage1_PageViewCreated">
       </telerik:RadMultiPage>
     </td>
 </tr>
 <tr>
   <td align="left"></td>
 </tr>
 <tr>
   <td align="left"></td>
 </tr>   
</table> 
</asp:Content>


 

0
Mark
Top achievements
Rank 1
answered on 08 Jul 2009, 12:34 AM
I had the same problem make sure you set the selected index on the RadMultiPage:

<

 

telerik:RadMultiPage ID="RadMultiPage1" runat="server" Width="100%"

 

 

SelectedIndex="0">

 

0
Rita
Top achievements
Rank 1
answered on 06 Apr 2010, 06:28 PM
Hi all, I'm having a similar situation.
I'm loading the user control at the first time and this is working ok, I'm adding the PageViews in code according to tab selection, but for some strange reason when I click any tab for the first time, even when the page is being added and selected, the tab doesn't change. If I click another tab, it works.

Does anyone know what could be happening. Thanks,
0
Andrew Gale
Top achievements
Rank 1
answered on 20 Apr 2010, 07:56 PM
Had the same problem, Mark's suggestion resolved it.
Thanks!
Tags
TabStrip
Asked by
Sami Aljafar
Top achievements
Rank 1
Answers by
Paul
Telerik team
Sami Aljafar
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Rita
Top achievements
Rank 1
Andrew Gale
Top achievements
Rank 1
Share this question
or