<%@ Page Language="VB" %>

<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Web.Script.Services" %>

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


<script runat="server">
   
    
Private _totalRowCount As Integer

    Sub 
Page_Load()
        _totalRowCount 
20
        
Profile("FWLinkcounters"""
        
Profile.Save()
    
End Sub

    Protected Sub 
buttonLRP_Click(ByVal sender As Object, _
           
ByVal As System.EventArgs)
        
Dim rowCounter As Integer = 0
        
Dim resultString As String = ""
        
Dim percentDone As Decimal
        For 
As Integer = To _totalRowCount - 1
            
resultString &(i + 1).ToString() & ". " & _
                TestLink(i) & 
"<br/>"
            
rowCounter +1
            
If _totalRowCount - Then
                
Profile("FWLinkcounters""done"
            
Else
                
percentDone rowCounter / _totalRowCount
                Profile(
"FWLinkcounters"= String.Format("{0} ({1}%)", _
                    CreateBar(percentDone, _totalRowCount, 
20), _
                    (Math.Ceiling(percentDone * 
100)).ToString())
            
End If
            
Profile.Save()
        
Next
        
Profile.Save()
        labelResults.Text 
resultString
        
        
' Hide counter
        
spanProgressDisplay.Visible = False
        
    End Sub
    
    Protected Sub 
buttonCancelLRP_Click(ByVal sender As Object, _
           
ByVal As System.EventArgs)
        Profile(
"FWLinkcounters""canceled"
        
Profile.Save()
        labelResults.Text 
"Canceled"

        
' Hide counter
        
Dim spanProgressDisplay As HtmlControl _
            
CType(FindControl("spanProgressDisplay"), HtmlControl)
        
        spanProgressDisplay.Visible 
= False
    End Sub
    
    Protected Function 
TestLink(ByVal rowCounter As IntegerAs String
        Dim 
resultString As String = ""
        
Thread.Sleep(1000)
        resultString 
"OK (200)"
        
Return resultString
    
End Function
        
    Protected Function 
CreateBar(ByVal percentDone As Decimal, _
            
ByVal totalCount As DecimalByVal size As DecimalAs String
        Dim 
barCount As Integer = System.Math.Ceiling(size * percentDone)
        
Dim bar As String = ""
        
For As Integer = To size
            
If i < barCount Then
                
bar &":"
            
Else
                
bar &"."
            
End If
        Next
        Return 
bar
    
End Function
</
script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>Update Panel </title>
<style>
body
{ font-family:verdana;
  font-size
:10pt;
  margin-left
:.75in;
  margin-right
:1.5in;
  margin-top
:.5in; }
H1 
{ font-size:14pt; }
.counterDisplay
{
   color
:red;
   font-weight
:bold;
}
</
style>

</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:ScriptManager 
           ID
="ScriptManager1" 
           runat
="server" > 
           
<Scripts>
              
<asp:ScriptReference Path="Progress.js" />
           </
Scripts>
        
</asp:ScriptManager>
    
</div>
    
<h1>ASP.NET AJAX: Displaying Progress</h1>
    
<p>This page illustrates one possible way to show the progress of a long-running
    process (LRP) by using ASP.NET AJAX. In this example, the LRP (which is faked)
    can update a persistent counter on the server at periodic intervals. The code
    stores the counter in a profile property.
</p>
    
<p>Client script in the page uses the Profile application service that is exposed
    by ASP.NET AJAX to poll the progress (by reading the profile property), and it 
    then displays results. 
</p>
    
    
<p/>
    
<hr />
        <
asp:UpdatePanel ID="UpdatePanel1" runat="server">
            
<ContentTemplate>
                
<asp:Button ID="buttonLRP" 
                    runat
="server" 
                    Text
="Start Long-Running Process" 
                    OnClick
="buttonLRP_Click" 
                    OnClientClick
="HideResults()" />

                <
asp:Button ID="buttonCancelLRP" 
                    runat
="server" 
                    Text
="Cancel Long-Running Process" 
                    OnClick
="buttonCancelLRP_Click"
                    OnClientClick
="HideResults()" /><br />
                <
br />
                <
asp:UpdateProgress ID="UpdateProgress1" runat="server">
                    
<ProgressTemplate>
                        Long-running process in progress ...
                    
</ProgressTemplate>
                
</asp:UpdateProgress>
                
<br />
                <
asp:Label ID="labelResults" runat="server" text="" />
            </
ContentTemplate>
        
</asp:UpdatePanel>
        
<br />
        <
br />
        <
button ID="buttonShowCounters" 
           onclick
="return buttonShowCounters_click()">Show Counters</button>
        
<button ID="buttonCancelCounters" 
           onclick
="return buttonCancelCounters_click()">Cancel Counters</button>
        
        
<br />
        <
br />
        <
span runat="server" class="counterDisplay" id="spanProgressDisplay"></span>
        
<br />
    </
form>
</body>
</html>

Colorized by: CarlosAg.CodeColorizer