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

6 posts, 0 answers
  1. Sami Aljafar
    Sami Aljafar avatar
    2 posts
    Member since:
    Dec 2008

    Posted 15 Feb 2009 Link to this post

    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>

  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 16 Feb 2009 Link to this post

    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.
  3. Sami Aljafar
    Sami Aljafar avatar
    2 posts
    Member since:
    Dec 2008

    Posted 16 Feb 2009 Link to this post

    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>


     

  4. Mark
    Mark avatar
    2 posts
    Member since:
    Jan 2009

    Posted 07 Jul 2009 Link to this post

    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">

     

  5. Rita
    Rita avatar
    3 posts
    Member since:
    Aug 2012

    Posted 06 Apr 2010 Link to this post

    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,
  6. Andrew Gale
    Andrew Gale avatar
    3 posts
    Member since:
    Apr 2010

    Posted 20 Apr 2010 Link to this post

    Had the same problem, Mark's suggestion resolved it.
    Thanks!
Back to Top