Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2822 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET AJAX > How to use UpdateProgress Control ASP.NET Ajax

How to use UpdateProgress Control ASP.NET Ajax

1 vote(s)
Rating: 5 out of 5
Article posted by Vuyiswamb on 12/2/2009 | Views: 12758 | Category: ASP.NET AJAX | Level: Beginner red flag


Windows applications are more stable than web application. Even if the web is not that stable like a windows application, there are lot advantages of building Web Applications and one thing that we remember as ex-Windows programmers is that the Forms did not Flicker in front of the eyes of the user. This irritates a lot of users. Microsoft came back with a good solution for this problem and they introduced Ajax. In this Article am going to show you how you can create Flicker Free pages.

Introduction

Every user that uses any type of Application  needs to know for sure that something is happening every time a button is Clicked, every time a page load, and every take an action has been taken. It is a responsibility of a software developer to put press indicator where needed so that the user can know that in the background something is happening. In this Article I am going to demonstrate to you, on how to use an Updateprogress Control from our Ajax toolbox section.

Background

 In this Article I am going explain how to create your own date picker with the Controls you have on your Visual Studio tool.

Using the code

We are going to user C# as our language.

Start

Open Visual Studio and Create a New Website. Automatically you will have an empty page defined for you like this

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

    </div>

    </form>

</body>

</html>

 

Go to Design View and you will notice there is nothing on your page. Now open your Toolbox and add a ScriptManager first and add an Updateprogress control in your page as depicted in the Diagram below.



Please note that the Scriptmanager must be the first control. It must appear before all Ajax controls. After you have added the Updateprogress control, add an UpdatePanel in the same section of Ajax in your toolbox. Add the gif images that represent progress, there are many gif’s that you can download on the net to mimic that. In your Updateprogress control there is a property that we will use to link our Updateprogress with our Update Panel “AssociatedUpdatePanel” change it to the name of your UpdatePanel as depicted in the diagram below.


The Last Part is to Add a button, make sure the Button is in the Updatepanel. We are going to use this button to trigger the partial post and make a longer thread that will keep our progress indicator running while the thread is still executing.

And after you have added these controls you should have something like this in your mark-up.

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

    Namespace="System.Web.UI" TagPrefix="asp" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager>

   

        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">

            <ProgressTemplate>

                <img alt="" src="ajax-loader_Loading.gif"

    style="width: 100px; height: 100px" />

            </ProgressTemplate>

       

        </asp:UpdateProgress>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">

        </asp:UpdatePanel>

        </div>

 

    </form>

</body>

</html>

 

 

And the Design view should look like this


 

Double click the button and to to the click event of the button and add the Following code.

 

   protected void cmdshow_Click(object sender, EventArgs e)

  {

        Thread.Sleep(2000);

  

  }

 

The above code, create a thread that will sleep after 2000 miliseconds, this will make sure that the UpdateProgress will show the Gif image to show as long as this thread still execute

 

That means your whole server side code should look like this

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Threading;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

    protected void cmdshow_Click(object sender, EventArgs e)

    {

        Thread.Sleep(2000);

  

    }

}

When you are done, press F5 to run your Project, you will see a page with only a button as depicted below.


If you click the button , a thread will start and you will see the UpdateProgress image as depicted

 

Conclusion

This is how you create a progress bar in ASP.NeT Ajax. This it is a good idea to add this in your application when needed. Remember too much of a thing makes a thing tallied.

Thank you for visiting DotnetFunda.

 

Vuyiswa Maseko

 

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:8 year(s)
Home page:http://www.Dotnetfunda.com
Member since:Sunday, July 06, 2008
Level:NotApplicable
Status: [Member] [MVP] [Administrator]
Biography:Vuyiswa Junius Maseko is a programmer and a moderator in ".NetFunda. Vuyiswa has been developing for 8 years now. his major strength are C# 1.1,2.0,3.0,3.5 and sql and his interest are in Silverlight,WPF,C#. He has been doing a lot of Silverlight development. He has been using .net since the beta version of it. He is also an online Trainer at www.Itfunda.com. Thanks to people like Sheo Narayan (.Netfunda) , Chris Maunder (codeproject), Colin Angus Mackay (codeproject), Dave Kreskowiak (Codeproject),.They have made vuyiswa what he is today.
>> Write Response - Respond to this post and get points
Related Posts

It is going to be full 4 years since I started writing articles. My First 4 years were a learning curve and no one could read my articles because I was just a newbie. I am hoping to write a book next year. Why I am saying that , is that I came across a book from a a reputable publisher, where an author badly explain a topic and he ended up pasting a generated that took 3 pages of his book. I will not do that and from the articles I have written before I have never done that, this means there is still room for people like Vuyiswa Maseko, Sheo Narayan and other guys like Abhi and QuestPond to write a book.

Sometimes in your Web application you might need your menu control to be available even when the user is scrolling down your page. Some Web Applications or Websites have a lot of contents on the page and when the user control down he forgets about the menus and sometimes it because a pain to always go up the page to find a menu. Sometimes it good if the menu can stay on the display while the user scrolls up and down. In this Article we are going to demonstrate on how to achieve this.

Maybe now you have accepted that the controls you see in your toolbox or those that is shipped with visual Studio does not have functionality that you might want to have on your web application or Silverlight. One needs to consider that the days of Classic asp are over, and one needs to accept that there are people out there who dedicated their time to fill your toolbox with controls that can do what you wanted to do. Me and Sheo we agreed that we are going to teach our visitors that sometimes you do not need to do things yourself. There are Companies like www.telerik.com , www.Infragistics.com , www.DevExpress.com who dedicated their time to make this possible at a certain fee. I will be writing articles on these nice controls and how to use them. The Last Control I used was the Scheduler provided by Telerik.

In this example I create a validation control. It checks if the TextBox is Empty it shows the error message.

This article describes how to use ASP.NET AJAX PageMethods to submit data to the server and get response. It also shows how to serialize object into JSON format and access its properties in JavaScript.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 7:28:30 AM