Refresh ASP.NET Label after Task Completes

Ok, so I did some searches, but I can't seem to find exactly what I'm looking for. I'm new to ASP.NET but not with C #. I had to create a page to handle a regular web service request to update the web store with data from the accounting software web service. The problem is that I need a page to load first and then run the update, otherwise the page will be disabled and the update will fail. There are only a few shortcuts on the rendered page and all I need to do this as the page will refresh so often and trigger the refresh. However, I need an update method to display the results on the screen. I have no problem running the update, just make sure the results are displayed. I have no buttons clicked, no forms.

Here is my page code:

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
<div class="pageHeader">
    <div class="caption">
        <h1><asp:Localize ID="Caption" runat="server" Text="Update of Order Status From NetSuite Into AbleCommerce"></asp:Localize></h1>
    </div>
</div>
<div>
        <asp:Label ID="Label0" runat="server"></asp:Label>
        <br /><br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <br /><br />
        <asp:Label ID="Label2" runat="server"></asp:Label>
        <br /><br />
        <asp:Label ID="Label3" runat="server"></asp:Label>
</div>
</asp:Content>

      




And here is my reverse code:

public partial class Template_Default : CommerceBuilder.Web.UI.AbleCommercePage
{
    private void PerformUpdate(object State)
    {
        Store _Store = StoreDataSource.Load(1);
        Token.Instance.InitStoreContext(_Store);
        String results = PontoonUpdate.soUpdate(); // method that performs the updates
        Label3.Text = "Update Completed. " + String.Format("{0:MM-dd-yyyy hh:mm:ss}", DateTime.Now + "\n\n" + results);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Label0.Text = "Update start time: " + String.Format("{0:MM-dd-yyyy hh:mm:ss}", DateTime.Now);
        Label1.Text = "Order updates will begin.";
        Label2.Text = "Processing...";
        if(!Page.IsPostBack)
            System.Threading.ThreadPool.QueueUserWorkItem(PerformUpdate);
    }
}

      

I know I am missing something and I know this due to my lack of experience with ASP.NET. If anyone has any pointers I would really appreciate it.


Ok, I found an answer to what I wanted to do. I was looking for something else and found this ...

http://www.simple-talk.com/dotnet/asp.net/implementing-waiting-pages-in-asp.net/

+3


source to share


1 answer


wrap your controls in an UpdatePanel. This is a poor AJAX man. Place your controls (or your entire page, for that matter) in a content template. Then, in the Triggers section, tell us which controls to look at and which events to catch. This will do the rest. In your case, from here you just need some kind of event to trigger. It could be javascript to fire an onLoad button or even an anchor event of some other control. It doesn't really matter.



<asp:UpdatePanel runat="server" ID="update">
    <ContentTemplate>
        <div class="pageHeader">
            <div class="caption">
                <h1><asp:Localize ID="Caption" runat="server" Text="Update of Order Status From NetSuite Into AbleCommerce"></asp:Localize></h1>
            </div>
        </div>
        <div>
                <asp:Label ID="Label0" runat="server"></asp:Label>
                <br /><br />
                <asp:Label ID="Label1" runat="server"></asp:Label>
                <br /><br />
                <asp:Label ID="Label2" runat="server"></asp:Label>
                <br /><br />
                <asp:Label ID="Label3" runat="server"></asp:Label>
        </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="generate" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

      

+1


source







All Articles