SIGN UP MEMBER LOGIN:    
ARTICLE

Working with AJAX Update progress control

Posted by Srinivas Kotra Articles | AJAX in C# November 11, 2009
This article shows how to display AJAX Update Progress on center position of gridview.
Reader Level:
Download Files:
 


In this article I am explaining about how to show Ajax Update progress at center of grid view.

Aspx code

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

<%@ Register Assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

    Namespace="System.Web.UI.WebControls" 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>Update Progress Sample</title>

 

    <script type="text/javascript">

        function onUpdating() {

            var updateProgressDiv = document.getElementById('upCustomer');

            var gridView = document.getElementById('gvUpdateProgress');

 

            var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);

            var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);

 

            var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);

            var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);

 

            Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);  

        }         

    </script>  

</head>

<body>

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

    <div>

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

        </asp:ScriptManager>

        <table border="0" cellpadding="0" cellspacing="0" width="100%">

            <tbody>

                <tr>

                    <td align="center" style="font-family: Calibri; background-color: #3366CC; color: #FFFFFF;

                        visibility: hidden; width: 100%">

                        UpdateProgress Sample

                    </td>

                </tr>

                <tr>

                    <td style="border: medium dotted Navy; font-family: Calibri; color: Purple; width: 100%;

                        border-color: Red; border-top-width: thick;">

                        <asp:UpdateProgress ID="upCustomer" AssociatedUpdatePanelID="upnlCustomer" runat="server">

                            <ProgressTemplate>

                                <div id="imgdivLoading" align="center" valign="middle" runat="server" style="border-style: dotted;

                                    padding: inherit; margin: auto; position: absolute; visibility: visible; vertical-align: middle;

                                    border-color: #000066 black black black; border-width: medium">

                                    <asp:Image ID="imgLoading" runat="server" ImageUrl="Images/loading.gif" Width="34px" />Loading...

                                </div>

                            </ProgressTemplate>

                        </asp:UpdateProgress>

                    </td>

                </tr>

                <tr>

                    <td>

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                </tr>

                <tr>

                    <td style="width: 100%">

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

                            <ContentTemplate>

                                <asp:GridView ID="gvUpdateProgress" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"

                                    AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None" Font-Names="Calibri"

                                    OnPageIndexChanging="gvUpdateProgress_PageIndexChanging" Width="100%" Caption="UpdateProgress Sample">

                                    <RowStyle BackColor="#EFF3FB" />

                                    <Columns>

                                        <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />

                                        <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />

                                        <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />

                                        <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />

                                        <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />

                                        <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />

                                        <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />

                                    </Columns>

                                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

                                    <PagerStyle BackColor="#2461BF" BorderStyle="None" ForeColor="White" HorizontalAlign="Right"

                                        Height="15px" />

                                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

                                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

                                    <EditRowStyle BackColor="#2461BF" />

                                    <AlternatingRowStyle BackColor="White" />

                                </asp:GridView>

                            </ContentTemplate>

                        </asp:UpdatePanel>

                    </td>

                </tr>

            </tbody>

        </table>

    </div>

    </form>

</body>

</html>

C# code


using System;

using System.Collections.Generic;

using System.Linq;

using System.Data;

using System.Data.SqlClient;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

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

{

    protected void Page_Load(object sender, EventArgs e)

    {

        gvUpdateProgress.Attributes.Add("onclick", " onUpdating();"); // ading java script to grid view.

        bindGrid();

    }

 

   
///
<summary>
/// Getting Customer table data from North wind database to bind gridview
/// </summary>
private void bindGrid()
{
SqlConnection conn = new SqlConnection("Trusted_Connection=yes;Addr=Localhost;Initial Catalog=Northwind");
SqlCommand cmdCustomer = new SqlCommand("SELECT [CustomerID],[CompanyName],[ContactName],[City],[PostalCode],[Country],[Phone] FROM Customers", conn);
SqlDataAdapter adptCustomer = new SqlDataAdapter(cmdCustomer);
DataSet dsCustomer = new DataSet();
adptCustomer.Fill(dsCustomer,
"Customer");
gvUpdateProgress.DataSource = dsCustomer.Tables[
"Customer"].DefaultView;
gvUpdateProgress.DataBind();
}

/// <summary>

///

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

   

    protected void gvUpdateProgress_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        System.Threading.Thread.Sleep(3000); // Loading image waiting period

        gvUpdateProgress.PageIndex = e.NewPageIndex;

        gvUpdateProgress.DataBind();

    }

}

Note:   I have used northwind database for this application. We can download northwind database from here :

http://code.msdn.microsoft.com/northwind/Release/ProjectReleases.aspx?ReleaseId=1401


This article is for single gridview controls. If we have more than one gridviews in your page we have to change javascript. If you have any concerns and comments please write to me.

Hope this example helps you.  Happy coding.

Login to add your contents and source code to this article
share this article :
post comment
 

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- insert_demo_sp_Expriment '','A',10.10,'Country','' -- select * from tblLists ALTER Procedure [dbo].[insert_demo_sp_Expriment] ( @AutoID bigint, @RecordStatus varchar(max), @UpdateID decimal(9,2), @Code CHAR(20), @Order int ) AS BEGIN DECLARE @MyOutput decimal(9,2) DECLARE @MyLastOutput decimal(9,2) DECLARE @OrderNo INT Set @MyOutput = 0 set @MyLastOutput = 0 set @OrderNo = 0 select @MyOutput = MAX(UpdateID) from dbo.tblLists where Code = ''+ @Code +'' select @OrderNo = Max([Order]) from dbo.tblLists where Code = ''+ @Code +'' select @MyLastOutput = ROUND(MAX(UpdateID),1,1) from dbo.tblLists if(@MyOutput != 0) BEGIN INSERT INTO dbo.tblLists ( UpdateID, RecordStatus, Code, [Order] ) Values ( @MyOutput + 00.01, 'A', @Code, @OrderNo + 1 ) END else BEGIN INSERT INTO dbo.tblLists ( UpdateID, RecordStatus, Code, [Order] ) Values ( @MyLastOutput + 1, 'A', @Code, 1 ) END END

Posted by Ketan Patel Jun 09, 2011

i download and tried this sample in IE browser its working fine but in firebox its not working

Posted by cuteboy thiru Dec 13, 2010

Keep the good work up.. very nice article.

Posted by Ravi Kiran Nov 11, 2009
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor