Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Hi
I have to display "Loading..." message when the data is pulled from backend to excel sheet which takes more than 5 min and once data fetching is done have to remove this message from screen.
I m able to show message on click of the button with the help of JQuery.
ASP.NET
<asp:Button ID="btnDownloadReport" Visible="true" runat="server" Text="Download" OnClientClick="$('.loading').show();" OnClick="btnDownloadReport_OnClick"/>

This is the DIV tag that is displaying the message.
<div class="loading" id="main" align="center"   runat="server">
<br />    
Loading. Please wait.<br />
<br />

Now the problem is I m unable to hide this message once the data is fetched.
Any code written after the method that pulls the data is not getting executed.
C#
protected void btnDownloadReport_OnClick(object sender, EventArgs e)
{
    GetData();
    // any code written here is not getting executed
}

Please help me. Its little urgent. Thanks.
Posted
Updated 7-Mar-13 3:44am
v2
Comments
bbirajdar 7-Mar-13 9:13am    
Hide it from the client side code

use script manager

ScriptManager.RegisterStartupScript(this, typeof(string), "script",
 "$('.loading').hide();", true);
 
Share this answer
 
Comments
anAlien2013 7-Mar-13 9:53am    
Hi Akhtar
Where should I put this code?
I tried putting it after the method that fetchs the data on buttonclick, but nothing happened.
Taha Akhtar 7-Mar-13 10:19am    
after GetData() and put scriptmanager in aspx page
Taha Akhtar 7-Mar-13 10:20am    
if nothing happend, then check what are the errors
Inject JavaScript code from server side using:
MSDN: RegisterClientScriptBlock Method[^]
MSDN: RegisterStartupScript Method[^]

Try something like:
C#
Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScript", "HideLoadingImage()", true);

In HideLoadingImage(), simply hide the image.

UPDATE:
It does. If the label is in the same update panel then that will get refreshed.

If it still troubles you, have a look at this article that will do what you seek: JavaScript Access to Page Controls after Ajax Update (via Update Panel)[^]
 
Share this answer
 
v2
Comments
anAlien2013 7-Mar-13 10:01am    
Yes, I m aware of this code but where should I put this code.
As I told before no code is getting executed written after GetData() method in buttonclick.
Sandeep Mewara 7-Mar-13 10:06am    
Updated answer.
anAlien2013 7-Mar-13 10:45am    
Getting this error - Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
Sandeep Mewara 7-Mar-13 11:47am    
That means your website isnot properly configured to use ASP.NET AJAX.

Create a new webproject with AJAX enabled template and try out. use the same config in your project post it.
anAlien2013 8-Mar-13 6:34am    
How to find out whether the AJAX is enabled or not? I m using VS2010 here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900