Using UpdateProgress on PageLoad

For some reason I cannot figure out how to display a loading message on the initial page_load of an aspx page that is inserting lots of records into a database. I am sure I am just being stupid and overlooking something simple but I cannot remember how to do this. Do I actually need an update panel and do I actually have to update an element in it to activate the updateprogress control, once all the records are inserted???

<%@ Page Title="" Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="registration2.aspx.vb" Inherits="registration2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBreadcrumbs" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphLeftMenu" Runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="cphRightContent" Runat="Server">
    <h1>User registration - Creating network</h1>
    <p>We will now create your educator network, enabling us to provide you with the best training available.</p>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DynamicLayout="true">
        <ProgressTemplate>
            <img src="/imgs/ajaxloader.gif" alt="loading" />
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="lbSuccess" runat="server" Text=""></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

Open in new window


Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Dim iUSerID As Integer = Request.QueryString("UID")

        Dim dtusers As DataTable = DBSelect.SelectUser(iUSerID, -1, "", "", -1, 0, 0, 0).Tables(0)
        Dim dlat1, dlat2, dlng1, dlng2 As Double
        Dim iuserid1, iuserid2 As Integer
        Dim idistance As Double
        Dim irecordid As Integer = 0

        For Each row In dtusers.Rows
            iuserid1 = row("id")
            dlat1 = row("latitude")
            dlng1 = row("longitude")
            'delete all
            DBDelete.DeleteUserDistance(-1, iuserid1, -1)
            DBDelete.DeleteUserDistance(-1, -1, iuserid1)

            Dim latlng1 As New GLatLng(dlat1, dlng1)
            Dim dtusers2 As DataTable = DBSelect.SelectUser(-1, -1, "", "", -1, 0, 0, 0).Tables(0)

            For Each _row In dtusers2.Rows
                iuserid2 = _row("id")
                dlat2 = _row("latitude")
                dlng2 = _row("longitude")
                Dim latlng2 As New GLatLng(dlat2, dlng2)
                idistance = latlng1.distanceFrom(latlng2) / 1000
                DBInsert.AddUserDistance(iuserid1, iuserid2, idistance)
            Next

        Next

        lbSuccess.Text = "Your network has now been created. Please click here to <a href=""/login.aspx"">login</a>"

    End Sub

Open in new window

swgdesignAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Johny BravoCommented:
Move your page_load code into a new function. Add timer to your page.Set some interval.

In timer_tick handler ,

protected void Your_Timer_Tick(object sender, EventArgs e)
{
    My_Timer_Name.Enabled = false;
    Your_Page_Load_Function(); // Function created in step 1 above)
}

protected void Your_Page_Load_Function()
{
    System.Threading.Thread.Sleep(5000); // In your case if your page always has delay you dont need to set this, for testing set the thread
 lbSuccess.Text = "Your network has now been created";
}
0
swgdesignAuthor Commented:
I think maybe I missed out a key bit of information...The updateprogress gif is not showing!!! (Sorry). My code executes correctly though and the records are inserted...just no loading gif...?

<asp:Content ID="Content4" ContentPlaceHolderID="cphRightContent" Runat="Server">
    <h1>User registration - Creating network</h1>
    <p>We will now create your educator network, enabling us to provide you with the best training available.</p>
    <asp:Timer ID="Timer1" runat="server"></asp:Timer>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DynamicLayout="true">
        <ProgressTemplate>
            <img src="/imgs/ajaxloader.gif" alt="loading" />
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="lbSuccess" runat="server" Text=""></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

Open in new window


Imports Subgurim.Controles
Imports System.Threading

Partial Class registration2
    Inherits System.Web.UI.Page
    Public DBSelect As New DBSelect
    Public DBInsert As New DBInsert
    Public DBDelete As New DBDelete


    Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
        Timer1.Enabled = False
        DoUserDistance(Request.QueryString("UID"))
        ' Function created in step 1 above)
    End Sub

    Public Sub DoUserDistance(UserID As Integer)
        Dim NewUserID As Integer = Integer.Parse(UserID)
        DBDelete.DeleteUserDistance(-1, NewUserID, -1, -1)
        DBDelete.DeleteUserDistance(-1, -1, NewUserID, -1)

        Dim dtusers As DataTable = DBSelect.SelectUser(NewUserID, -1, "", "", -1, 0, 0, 0).Tables(0)
        Dim dlat1, dlat2, dlng1, dlng2 As Double
        Dim iuserid1, iuserid2 As Integer
        Dim idistance As Double
        Dim irecordid As Integer = 0

        For Each row In dtusers.Rows
            iuserid1 = row("id")
            dlat1 = row("latitude")
            dlng1 = row("longitude")

            Dim latlng1 As New GLatLng(dlat1, dlng1)
            Dim dtusers2 As DataTable = DBSelect.SelectUser(-1, -1, "", "", -1, 0, 0, 0).Tables(0)
            For Each _row In dtusers2.Rows
                iuserid2 = _row("id")
                dlat2 = _row("latitude")
                dlng2 = _row("longitude")
                Dim latlng2 As New GLatLng(dlat2, dlng2)
                idistance = latlng1.distanceFrom(latlng2) / 1000
                DBInsert.AddUserDistance(iuserid1, iuserid2, idistance)
                DBInsert.AddUserDistance(iuserid2, iuserid1, idistance)
            Next
        Next

        'delete entries where distance = 0
        DBDelete.DeleteUserDistance(-1, -1, -1, 0)
    End Sub


    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        System.Threading.Thread.Sleep(5000)
        ' In your case if your page always has delay you dont need to set this, for testing set the thread
        lbSuccess.Text = "Your education network has now been created!"
    End Sub
End Class

Open in new window

0
swgdesignAuthor Commented:
I have fixed this the way I want by updating a label with text outputted from the Page_Load event and then hiding it so the animation is triggered until the code has stopped.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
swgdesignAuthor Commented:
This was the only solution that worked for me. The suggested solution did not do anything different than my original code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.