ASP.NET AJAX: Firing an UpdatePanel after the page load is complete

后端 未结 7 1129
再見小時候
再見小時候 2021-02-15 07:52

I\'m sure this is easy but I can\'t figure it out:

I have an ASP.NET page with some UpdatePanels on it. I want the page to completely load with some \'Please w

7条回答
  •  滥情空心
    2021-02-15 08:12

    I fiddled around with the ScriptManager suggestions - which I reckon I would have eventually got working but it seems to me that the Timer idea is easier to implement and not really(!) that much of a hack?!

    Here's how I got my panel updated after the initial page render was complete...

    default.aspx

        <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXPostLoadCall._Default" %>
    
    
    
    
    
        Untitled Page
    
    
        

    And now for a magic trick...

    Something magic is about to happen...

    and the code behind default.aspx.cs reads

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    
    namespace AJAXPostLoadCall
    {
        public partial class _Default : System.Web.UI.Page
        {
    
            protected void Page_Load(object sender, EventArgs e)
            {
            }
    
            public void DoMagic()
            {
                Label1.Text = "Abracadabra";
            }
    
            protected void Timer1_Tick(object sender, EventArgs e)
            {
                // Do the magic, then disable the timer
                DoMagic();
                Timer1.Enabled = false;
            }
    
        }
    }
    

    So, the page loads up and the Timer (contained within the UpdatePanel) fires 2 secs after the page has loaded up (I think - I'm not sure when the Timer actually starts?). The label text is rewritten and then the Timer is disabled to stop any more updates.

    Simple enough - but can you purists out there tell me if this is a Horrible Hack?

提交回复
热议问题