Load on Demand runs controls multiple times

12 posts, 0 answers
  1. Scott MacDonald
    Scott MacDonald avatar
    12 posts
    Member since:
    Jun 2008

    Posted 08 Jan 2009 Link to this post

    I used a sample from the Telerik site and tweaked the control files to run a subroutine on each tab load. I find that when the first tab is is selected and loaded, the subroutine for that control runs. However when I click on the second tab the first tab's subroutine runs and then the second tab's subroutine runs. When I click the third tab, the first two subroutines run and then the third subroutine runs. After that I can freely click through all the tabs and all the information is there as it is supposed to be. But to get here the page ran a number of the same subroutines multiple times. Shouldn't the load on demand only run the subroutine associated with the page once and as you click on the other tabs only run their subroutines on demand? Then if this happens I would still hope that all the information will still be retained for each tab when reclicked? If my assumptions are correct, what is wrong with my sample code or what am I missing?  Thank you for your help, much appreciated.

    **************

    ASPX

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="C_Test.aspx.vb" Inherits="SMARTmig.C_Test" %>

     

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title>C Test</title>

        <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR" />

        <meta content="Visual Basic 7.0" name="CODE_LANGUAGE" />

        <meta content="JavaScript" name="vs_defaultClientScript" />

        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema" />

           <script type="text/javascript">

               

                function onTabSelecting(sender, args)

                {

                    if (args.get_tab().get_pageViewID())

                    {

                        args.get_tab().set_postBack(false);

                        //--alert(args.get_tab().get_pageViewID())

                        //--alert(args.get_tab().get_postBack())

                   }

                }

               

            </script>

    </head>

    <body>

        <form id="form1" method="post" runat="server">

            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

            </telerik:RadScriptManager>

            <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server">

                <table cellspacing="0" cellpadding="15" width="100%" border="0">

                    <tr>

                        <td bgcolor="#f3f3f3">

                            &nbsp;</td>

                    </tr>

                    <tr>

                        <td bgcolor="#f3f3f3">

                            &nbsp;</td>

                    </tr>

                    <tr>

                        <td bgcolor="#f3f3f3">

                            &nbsp;</td>

                    </tr>

                    <tr>

                        <td bgcolor="#f3f3f3">

                            &nbsp;</td>

                    </tr>

                    <tr>

                        <td bgcolor="#f3f3f3">

                            <asp:Image runat="server" ID="LoadingImage1" ImageUrl="../images/loading.gif" AlternateText="Loading..." />

                        </td>

                    </tr>

                </table>

            </telerik:RadAjaxLoadingPanel>

            &nbsp;

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

     

     

            <table cellspacing="0" cellpadding="15" width="100%" border="0">

                <tr>

                    <td bgcolor="#f3f3f3">

                        <font face="Arial, Helvetica, sans-serif" color="#732928" size="2"><strong>Click the

                            tabs below for further details on each phase of the SMART process.</strong></font></td>

                </tr>

            </table>

            <table cellspacing="0" cellpadding="15" width="100%" border="0">

                <tr>

                    <td bgcolor="#f3f3f3" colspan="2">

                        <telerik:RadTabStrip OnClientTabSelecting="onTabSelecting" ID="RadTabStrip1"

                            SelectedIndex="0" runat="server" MultiPageID="RadMultiPage1" Skin="Gray" Align="Justify"

                            Width="800px" Orientation="HorizontalTop">

                        </telerik:RadTabStrip>

                        <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0"

                            CssClass="MultiPage" Width="800px">

                        </telerik:RadMultiPage>

                    </td>

                </tr>

            </table>

        </form>

    </body>

    </html>

     

    VB.NET

    Imports System

    Imports System.Web

    Imports System.Web.UI

    Imports System.Web.UI.WebControls

    Imports System.Data

    Imports System.Data.SqlClient

    Imports Telerik.Web.UI

    Imports Microsoft.VisualBasic

     

    Namespace SMARTmig

      Partial Class C_Test

        Inherits System.Web.UI.Page

     

     

    #Region " Web Form Designer Generated Code "

     

        'This call is required by the Web Form Designer.

        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

     

        End Sub

     

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

          'CODEGEN: This method call is required by the Web Form Designer

          'Do not modify it using the code editor.

          InitializeComponent()

        End Sub

     

    #End Region

     

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

          If Not Page.IsPostBack Then

            AddTab("TabOne")

            AddTab("TabTwo")

            AddTab("TabThree")

            AddPageView(RadTabStrip1.FindTabByText("TabOne"))

     

          End If

     

     

     

        End Sub

     

        Private Sub AddTab(ByVal tabName As String)

          Dim tab As RadTab = New RadTab

          tab.Text = tabName

          RadTabStrip1.Tabs.Add(tab)

     

        End Sub

     

        Protected Sub RadTabStrip1_TabClick(ByVal sender As Object, ByVal e As RadTabStripEventArgs) Handles RadTabStrip1.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.Text

          RadMultiPage1.PageViews.Add(pageView)

          pageView.CssClass = "pageView"

          tab.PageViewID = pageView.ID

     

        End Sub

     

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

          Dim userControlName As String = e.PageView.ID + "VB.ascx"

          Dim userControl As Control = Page.LoadControl(userControlName)

          userControl.ID = e.PageView.ID & "_userControl"

          e.PageView.Controls.Add(userControl)

     

        End Sub

     

      End Class

     

     

    End Namespace

     

    ASCX   for tab one

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TabOneVB.ascx.vb" Inherits="Admin_TabOneVB" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

           <table cellspacing="0" cellpadding="15" width="100%" border="1">

                <tr>

                    <td bgcolor="#f3f3f3">

                        <img href="#" alt="" src="../images/org_assess_bckgrd.gif" /><br />

                        <br />

                        <font face="Arial, Helvetica, sans-serif" color="#732928" size="2"><strong>Assessment!</strong><br />

                            <br />

                            <strong>When to clients:</strong><ul>

                                <li>They are looking whom.</li>

                                <li>They want to align skills </li>

                                <li>They want to develop an.</li>

                                <li>They want to costs.</li>

                                <li>They want to document</li>

                                <li>They know that requirements.</li>

                            </ul>

                        </font>&nbsp;

                        <asp:Label runat="server" ID="asmt"></asp:Label>

                    </td>

                </tr>

            </table>

     

    ASCX.VB   for tab one

     

     

     

    Imports System

    Imports System.Web

    Imports System.Web.UI

    Imports System.Web.UI.WebControls

    Imports System.Data

    Imports System.Data.SqlClient

    Imports Telerik.Web.UI

    Imports Microsoft.VisualBasic

     

    Partial Class Admin_TabOneVB

      Inherits System.Web.UI.UserControl

     

     

     

    #Region " Web Form Designer Generated Code "

     

      'This call is required by the Web Form Designer.

      <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

     

      End Sub

     

      Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

        'CODEGEN: This method call is required by the Web Form Designer

        'Do not modify it using the code editor.

        InitializeComponent()

      End Sub

     

    #End Region

     

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here

     

        Call RunOne()

     

     

      End Sub

     

     

      Public Sub RunOne()

        'SQL Database connection

     

        Dim sConnect As New SMARTmig.ConnectSMART.Connections

        Dim cn As New SqlConnection

        cn.ConnectionString = sConnect.GetConnectionString

     

     

        Dim ta As String = Request.QueryString("ta")

        Dim myCM As New SqlCommand

        myCM.Connection = cn

        myCM.CommandType = CommandType.StoredProcedure

        myCM.CommandText = "Query_TA_RegStatsV2"

     

        Dim myParm As New SqlParameter("@BeginDT", SqlDbType.VarChar)

     

        myParm.Value = "1/1/2009"

        myParm.Direction = ParameterDirection.Input

        myCM.Parameters.Add(myParm)

     

        myParm = New SqlParameter("@EndDT", SqlDbType.VarChar)

        myParm.Value = "3/1/2009"

        myParm.Direction = ParameterDirection.Input

        myCM.Parameters.Add(myParm)

     

        myParm = New SqlParameter("@TA", SqlDbType.VarChar)

        myParm.Value = "%gretz%"

        myParm.Direction = ParameterDirection.Input

        myCM.Parameters.Add(myParm)

     

        Dim myCMD As New SqlDataAdapter

        myCMD.SelectCommand = myCM

        Dim es As DataSet = New DataSet

        myCMD.Fill(es, "dAP")

        Dim myDataTable As DataTable

        myDataTable = es.Tables("dAP")

        cn.Close()

        'Response.Write("test")

        Dim myRow As DataRow

        Dim currRows() As DataRow = myDataTable.Select(Nothing, Nothing, DataViewRowState.CurrentRows)

        For Each myRow In currRows

          asmt.Text = myRow("lastname")

          Exit For

        Next

      End Sub

     

    End Class

     

     

    ASCX  for Tab Two

     

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TabTwoVB.ascx.vb" Inherits="Admin_TabTwoVB" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

             <table cellspacing="0" cellpadding="15" width="100%" border="1">

                <tr>

                    <td bgcolor="#f3f3f3">

                        <img href="#" alt="" src="../images/org_assess_bckgrd.gif" /><br />

                        <br />

                        <font face="Arial, Helvetica, sans-serif" color="#732928" size="2"><strong>Definition!</strong><br />

                            <br />

                            <strong>When to clients:</strong><ul>

                                <li>They are looking whom.</li>

                                <li>They want to align skills </li>

                                <li>They want to develop an.</li>

                                <li>They want to costs.</li>

                                <li>They want to document</li>

                                <li>They know that requirements.</li>

                            </ul>

                        </font>&nbsp;

                        <asp:Label runat="server" ID="def"></asp:Label>

                    </td>

                </tr>

            </table>

     

     

     

    ASCX.VB   for tab two

     

    Imports Microsoft.VisualBasic

     

    Partial Class Admin_TabTwoVB

      Inherits System.Web.UI.UserControl

     

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here

     

        RunTwo()

     

     

      End Sub

     

     

      Public Sub RunTwo()

        'SQL Database connection

     

        Dim sConnect As New SMARTmig.ConnectSMART.Connections

        Dim cn As New SqlConnection

        cn.ConnectionString = sConnect.GetConnectionString

     

     

        Dim ta As String = Request.QueryString("ta")

        Dim myCM As New SqlCommand

        myCM.Connection = cn

        myCM.CommandType = CommandType.StoredProcedure

        myCM.CommandText = "Query_TA_RegStatsV2"

     

        Dim myParm As New SqlParameter("@BeginDT", SqlDbType.VarChar)

     

        myParm.Value = "1/1/2009"

        myParm.Direction = ParameterDirection.Input

        myCM.Parameters.Add(myParm)

     

        myParm = New SqlParameter("@EndDT", SqlDbType.VarChar)

        myParm.Value = "3/1/2009"

        myParm.Direction = ParameterDirection.Input

        myCM.Parameters.Add(myParm)

     

        myParm = New SqlParameter("@TA", SqlDbType.VarChar)

        myParm.Value = "%larson%"

        myParm.Direction = ParameterDirection.Input

        myCM.Parameters.Add(myParm)

     

        Dim myCMD As New SqlDataAdapter

        myCMD.SelectCommand = myCM

        Dim es As DataSet = New DataSet

        myCMD.Fill(es, "dAP")

        Dim myDataTable As DataTable

        myDataTable = es.Tables("dAP")

        cn.Close()

        'Response.Write("test")

        Dim myRow As DataRow

        Dim currRows() As DataRow = myDataTable.Select(Nothing, Nothing, DataViewRowState.CurrentRows)

        For Each myRow In currRows

          def.Text = myRow("lastname")

          Exit For

        Next

      End Sub

     

    End Class

     

     

     

  2. Renan
    Renan avatar
    12 posts
    Member since:
    Jun 2008

    Posted 15 Jan 2009 Link to this post

    We have same issue, our page(s) (.aspx) that are loaded from RadMultipage are reloaded when you add new Tab and equivalent MultiPage.

    Hi Telerik Team,

    Any suggestion?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 16 Jan 2009 Link to this post

    Hi there,

    Unfortunately, the provided information doesn't help us much in reproducing the error. It will be best if you open a formal support ticket and can send us a simple running project (incl. CSS, images, DB backup and so on) demonstrating the problems. In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.

    Kind regards,
    Paul
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Scott MacDonald
    Scott MacDonald avatar
    12 posts
    Member since:
    Jun 2008

    Posted 16 Jan 2009 Link to this post

    Thank you paul, I do have a formal support ticket open and will add the logic there as suggested. Thank you
  6. Newton
    Newton avatar
    26 posts
    Member since:
    Sep 2005

    Posted 26 Jan 2009 Link to this post

    Hello,

    I have this issue too. 
    Is there a solution?


    Regards,
    Newton Dantas
  7. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 27 Jan 2009 Link to this post

    Hi Newton,

    Our load on demand example loads all previously loaded tabs and updates them. This is required for the proper update of ViewState. As a result the code in all user controls is executed. You can raise a flag in ViewState to mark a control as already loaded and avoid executing the code more than once. Hare is a short code snippet:

    If ViewState("Loaded") = False 
            'Call your code 
           ViewState("Loaded") = True 
    Then 


    Greetings,
    Paul
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 29 Jun 2010 Link to this post

    Hmm, is it still "load on demand" then?
    If it loads everything, it's not really load on demand, is it??
    --> I'd call it "append and reload everything"...
    I thought the purpose here was to load little by little, especially in a scenario where each tab is quite loaded; I was testing this because of performance issues... But if it's going to reload everything on each tab click; might as well go for a full postback: it would be quicker for the user and quicker to program...
  9. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 30 Jun 2010 Link to this post

    Hello Nicolai,

    Actually it reloads only already loaded user controls and this is required, because dynamically loaded user controls are not persistent and should be added on every postback - this is general asp.net approach that is not related to the controls.

    Greetings,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 30 Jun 2010 Link to this post

    I see.
    I think it would make more sense to clear the others and load only the displayed one... Unless they have to interact with each other in some way, it just seems more logical to free the browser and server memory and reload only the displayed UC..
    Even when navigating back to an already viewed tab, it makes more sense to go fetch the newest data on it..
    Maybe iit's just my scenarios, I don't know...
  11. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 30 Jun 2010 Link to this post

    Hello Nicolai,

    You can set RenderSelectedPageOnly property of the multipage in this case. But note that you should allow the tabstrip to postback for every tab in order to render the needed pageview.

    Best wishes,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Thomas
    Thomas avatar
    7 posts
    Member since:
    Sep 2010

    Posted 27 Sep 2010 Link to this post

    Hi,

    is there a full exapmle for this issue?

    My scenario is similar:

    One aspx Page with a Tabstrip
    3 ascx Controls.
    They are all independent from each other.

    Only the requested ascx should be loaded.

    I can't fit the suggested snippets togehter.

    Can anyone give me a short example ?

    Kind regards Thomas
  13. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 30 Sep 2010 Link to this post

    Hello Thomas,

    You can use this demo as a base, you just need to set RenderSelectedPageOnly property of the multipage to "true" and AutoPostBack property of the tabstrip also to "true".

    Greetings,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017