Silentbob
Silentbob

Reputation: 3065

Display loading gif while web page loads

I am using VS 2013 (asp.net, VB).

I have a web page that has a sub that executes a lot of code. The sub runs when the page loads but also when a button is clicked. The code within the sub basically imports values from a database and then saves them to an excel document which then performs a solver calculation and saves the excel document.

Anyway, the page load time is quite long so I want to display a loading GIF whilst the sub is executed.

I thought I could do something like the following.

The gif:

<div id="loadingGif" runat="server">
    Loading. Please Wait....<br /><br />
    <img src="images/RTO_Loader.GIF" alt=""/>
</div>

The page load:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    loadingGif.Visible = True
    exportToExcelEvent()
    loadingGif.Visible = False
End Sub

This doesn't work. I don't get any errors and the excel document saves fine. I haven't been able to find any understandable help on this. From what I have read threading may solve this but I cant seem to get it working.

Thanks if you can help.

Upvotes: 3

Views: 3648

Answers (1)

PrzemG
PrzemG

Reputation: 795

Remove runat="server" attribute from 'loadingGif' div and replace it with:

style="display:none;"

Also remove lines from Page_Load that change visibility of that div.

Add OnClientClick event to button and set it to:

OnClientClick="document.getElementById('loadingGif').style.display = 'block';"

You can move that javascript to functiona and call function instead.

Another option is to use Ajax UpdatePanel with UpdateProgress.

Upvotes: 2

Related Questions