Start callback immediately after page loaded

Last post 07-24-2007 2:14 AM by Jin-Yu Yin - MSFT. 8 replies.

Sort Posts:

  • Start callback immediately after page loaded

    07-18-2007, 4:47 PM
    • Member
      22 point Member
    • miksh
    • Member since 03-16-2004, 3:23 AM
    • Posts 33

    I have a UpdatePanel on the page. But instead of the standard scenario when the page is completly rendered on the first call I need to display an empty panel content with the loading indicator and start update immediately after the page has been loaded.

    How to impelment it?

  • Re: Start callback immediately after page loaded

    07-18-2007, 8:18 PM
    • Star
      13,541 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,236
    • ASPInsiders
      TrustedFriends-MVPs
    You could use the OnLoad event of the UpdatePanel to render the panel's contents, and IsPostBack to not render that content on the initial page load.  Then, in your client script, call __doPostBack("UpdatePanel", '') from pageLoaded() to trigger that UpdatePanel_Load code.
    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: Start callback immediately after page loaded

    07-18-2007, 8:58 PM
    • Member
      22 point Member
    • miksh
    • Member since 03-16-2004, 3:23 AM
    • Posts 33

    Thanks, I'll try but IMHO this hack might be not compatible with the next ajax versions.

    I forgot to mention that my UpdatePanel is updated by a timer. Is there any way to fire the timer's OnTick event immediately?
    Any other ideas to trigger the UpdatePanel on client-side?

  • Re: Start callback immediately after page loaded

    07-18-2007, 9:46 PM
    • Star
      13,541 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,236
    • ASPInsiders
      TrustedFriends-MVPs
    Which part are you uncomfortable with?
    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: Start callback immediately after page loaded

    07-18-2007, 10:53 PM
    • Contributor
      2,460 point Contributor
    • Steve Marx
    • Member since 05-26-2006, 8:35 PM
    • Microsoft
    • Posts 643

    Here are a couple more ideas I blogged a while ago: http://smarx.com/posts/delayed-load-with-an-updatepanel.aspx.

    Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
  • Re: Start callback immediately after page loaded

    07-19-2007, 7:24 AM
    • Member
      22 point Member
    • miksh
    • Member since 03-16-2004, 3:23 AM
    • Posts 33

    Usually I try to avoid any explicit __doPostBack(...) calls.

  • Re: Start callback immediately after page loaded

    07-19-2007, 11:14 AM
    • Star
      13,541 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,236
    • ASPInsiders
      TrustedFriends-MVPs

    They really aren't anything to worry about, in my experience.  If you've ever used a GridView, DataGrid, LinkButton, or half a dozen other common controls, you're already relying on the __doPostBack() mechanism.

    If it feels better to abstract how you inject them, you could use ClientScript.GetPostBackEventReference(UpdatePanel1, "") to generate the actual call.
     

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: Start callback immediately after page loaded

    07-19-2007, 11:24 AM
    • Member
      22 point Member
    • miksh
    • Member since 03-16-2004, 3:23 AM
    • Posts 33

    gt1329a:
    If it feels better to abstract how you inject them, you could use ClientScript.GetPostBackEventReference(UpdatePanel1, "") to generate the actual call.

    This looks more resanable, thanks. So far, I added a hidden button inside an UpdatePanel and make a javasript's click on it to trigger the update. But I like your approach more.

     

  • Re: Start callback immediately after page loaded

    07-24-2007, 2:14 AM
    Answer

    Hi

    If the contents of the panel are very large,you can delay by several seconds to load the content.

    You don't need to load it when the whole page load.when the whole page is loading,set the panel unvisible.

    Then load the content of the panel.

    Code as follow:

    <%@ Page Language="C#" %>

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

    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(3000);
            TextBox1.Text = DateTime.Now.ToString();
        }
    </script>

    <script type="text/javascript">
    function delayLoad()
    {
    document.getElementById("<%= Button1.ClientID %>").click();
    document.getElementById("<%= UpdateProgress1.ClientID %>").style.display = "block";
    }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body onload="setTimeout('delayLoad()',3000)">
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    <div visible="true"><asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
                <ProgressTemplate>
                    Waiting..............
                </ProgressTemplate>
            </asp:UpdateProgress>
        </div>
        </form>
    </body>
    </html>

    More informatin,see:Delaying Content Load using Timer and UpdatePanel AND Controlling visibility of contents of collapsiblepanel

    Thanks

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
Page 1 of 1 (9 items)