Click here to Skip to main content
6,630,289 members and growing! (22,982 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Simple ‘In-Progress’ Message for Time Consuming Tasks in ASP.NET Pages

By Kiran Kumar Veerabatheni

‘In-Progress’ Message & Disabling controls in ASP.NET Pages using JavaScript
C# (C# 1.0, C# 2.0, C# 3.0, C# 4.0), Javascript, CSS, HTML, XHTML, JScript .NET, .NET (.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0), ASP, ASP.NET, Visual Studio (VS.NET2003, VS2005, VS2008), ADO.NET, PHP, WebForms, Ajax, Architect, Dev, QA, Design
Version:2 (See All)
Posted:4 Jul 2009
Views:5,415
Bookmarked:29 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 3.06 Rating: 4.38 out of 5

1

2

3
3 votes, 60.0%
4
2 votes, 40.0%
5

Introduction

We often come across web pages which take more time to perform a task when the user clicks a Button control. Users often tend to click the other options of the page during the delay – which causes unexpected behavior and strange results of the page. It is always sensible to display an ‘In-Progress’ message when your web page is taking more than a few seconds to perform the server side task. There are other complex ways of doing the same using Ajax .NET controls like ‘Modal Popup Extender’, Modal window, iframe,... etc.

My solution is a simple JavaScript which is fast, light weight & also does not disturb your ASP.NET server side code. This should also work fine for other web programming languages like PHP, JSP, Cold Fusion,... etc.

Scenario

I have an ASPX page which retrieves data and binds to an ASP.NET Grid on a Button click. This process takes 30 seconds to display the results, during which the page has to:

  1. Display an ‘In-Progress’ message (with a GIF image for animated feel) 
  2. Restrict the user from accessing other controls when the ‘in-Process’ message is displayed to avoid unwanted post backs.

Process Message Display

Solution

  1. Add a div tag to the HTML code, to display the message and image. Set the visibility of the div tag as hidden.
    <div id=""ProcessingWindow"" visible=""false"">
        <img src="%22loading.gif%22" />
    </div>
  2. JavaScript function ShowProcessMessage() to Div visible’, and add the Progress message and image to the innerHTML of the Div tag.
    Note: Include the GIF image to display the image to get the animation running.
    <script language ="javascript" type="text/javascript" >
        
      ShowProcessMessage = function(PanelName)
         	 {
    		//Sets the visibility of the Div to 'visible'
         		document.getElementById(PanelName).style.visibility = "visible";
    
                    /* Displays the  'In-Process' message through the innerHTML.
                       You can write Image Tag to display Animated Gif */
    
                        document.getElementById(PanelName).innerHTML = 
    					'In-Process...Please Wait ... '; 
    
                    //Call Function to Disable all the other Controls
                 	DisableAllControls ('btnLoad');
    
                 	return true; //Returns the control to the Server click event
        	  }
    
    </script>
  3. JavaScript function DisableAllControls() to disable all the controls except the control to raise the event and also the hidden types (ASP.NET Event handlers and Viewstate):
    <script language ="javascript" type="text/javascript" >
    
    DisableAllControls = function(CtrlName)
    {	
         var elm;
         /*Loop for all the controls of the page.*/
         for(i = 0; i <= document.forms[0].elements.length -1 ; i++) 
          { 
                     /* 1.Check for the Controls with type 'hidden' – 
                     which are ASP.NET hidden controls for Viewstate and EventHandlers. 
                     It is very important that these are always enabled, 
    	        for ASP.NET page to be working.
                        2.Also Check for the control which raised the event 
    	        (Button) - It should be active. */
    
            elm = document.forms[0].elements[i];
    
      	if( (elm.name == CtrlName) || (elm.type =='hidden') )
                     { 
                        elm.disabled=false;	 
                     }
            	else
                     {
                         elm.disabled=true; //Disables all the other controls
                     }
         	   } 
    }
    
    </script>
  4. Call the JavaScript function on the OnClientClick event of the Button. The page control first hits the client side function and then goes to the Server side event handler.
    <asp:Button ID="btnLoad" runat="server" onclick="btnLoad_Click" 
    Text="Get Songs List" OnClientClick ="ShowProcessMessage('ProcessingWindow')" />

Final Words

This is a common problem faced by most of us while developing bigger functionalities in web pages. This should also work fine for other web programming languages like PHP, JSP, Cold Fusion,... etc.

Hope this solution would be helpful.

Happy programming!

History

  • 4th July, 2009: Initial post

License

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

About the Author

Kiran Kumar Veerabatheni


Member
Senior Developer with over 6+ years of experience in developing Web-based Applications using Microsoft.Net.
Occupation: Software Developer
Company: IBM
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
Generalcheck for Page validation Pinmemberclazarev20:53 7 Jul '09  
GeneralRe: check for Page validation PinmemberKiran Kumar Veerabatheni1:53 2 Sep '09  
Generalpretty cool PinmemberDaniel M. Camenzind21:37 6 Jul '09  
GeneralRe: pretty cool - but not working properly PinmemberDaniel M. Camenzind22:26 6 Jul '09  
GeneralFigured out how to make it work PinmemberBigJim618:46 7 Jul '09  
GeneralCorrecting my correction PinmemberBigJim619:20 7 Jul '09  
GeneralRe: Correcting my correction PinmemberKiran Kumar Veerabatheni1:31 2 Sep '09  
GeneralRe: pretty cool PinmemberKiran Kumar Veerabatheni21:35 2 Sep '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Jul 2009
Editor: Deeksha Shenoy
Copyright 2009 by Kiran Kumar Veerabatheni
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project