<%@ Page Title="Custom Progress Display" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxUploader" Namespace="AjaxUploader.Controls" TagPrefix="au" %> 
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">Custom Progress Display - AjaxUploader v5.2 Demos</asp:Content>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeaderTitle" runat="server">Custom Progress Display</asp:Content> 
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> 
<div class="demo-card"> <div class="demo-card-header">Custom Progress via onTaskProgress</div> <div class="demo-card-body"> <p class="demo-description"> Build a fully custom progress display using the onTaskProgress callback. This example
 shows a circular progress indicator, speed gauge, and detailed statistics.
 </p> <div class="demo-expect"><strong>What you should see:</strong> progress events driving your own display - percentage, transferred bytes and speed rendered in page elements you control.</div> <au:AjaxFileUpload ID="Uploader1" runat="server" /> <div class="mt-3 d-flex align-items-center gap-4"> <div class="text-center"> <svg id="circleProgress" width="100" height="100" viewBox="0 0 100 100"> <circle cx="50" cy="50" r="42" fill="none" stroke="#e9ecef" stroke-width="8"/> <circle id="progressCircle" cx="50" cy="50" r="42" fill="none" stroke="#0d6efd"
 stroke-width="8" stroke-dasharray="264" stroke-dashoffset="264"
 transform="rotate(-90 50 50)" stroke-linecap="round"/> <text id="percentText" x="50" y="54" text-anchor="middle" font-size="18" fill="#333">0%</text> </svg> </div> <div class="flex-grow-1"> <div class="mb-1"><small class="text-muted">File:</small> <span id="fileName">--</span></div> <div class="mb-1"><small class="text-muted">Speed:</small> <span id="speed">--</span></div> <div class="mb-1"><small class="text-muted">Uploaded:</small> <span id="uploaded">--</span></div> <div><small class="text-muted">ETA:</small> <span id="eta">--</span></div> </div> </div> <div class="code-panel"> <pre><code>var uploader = AjaxUploader.getInstance('Uploader1');
uploader.on('taskProgress', function(task) {
 var pct = clampPercent(task.percent);
 var offset = 264 - (264 * pct / 100);
 circle.setAttribute('stroke-dashoffset', offset);
 percentText.textContent = pct + '%';
 speed.textContent = AjaxUploader.formatSize(task.speed) + '/s';
 uploaded.textContent = AjaxUploader.formatSize(task.loaded) +
 ' / ' + AjaxUploader.formatSize(task.total);
});</code></pre> </div> </div>
</div> 
</asp:Content> 
<asp:Content ID="ScriptsContent" ContentPlaceHolderID="ScriptsContent" runat="server">
<script> var circle = document.getElementById('progressCircle');
 var percentText = document.getElementById('percentText');
 var fileName = document.getElementById('fileName');
 var speed = document.getElementById('speed');
 var uploaded = document.getElementById('uploaded');
 var eta = document.getElementById('eta');
 function clampPercent(value) {
 var pct = Number(value);
 if (!isFinite(pct)) return 0;
 return Math.max(0, Math.min(100, Math.round(pct)));
 }

 var uploader = window.AjaxUploader && AjaxUploader.getInstance ? AjaxUploader.getInstance('Uploader1') : null;
 if (uploader) {
 uploader.on('taskStart', function(task) {
 if (fileName) fileName.textContent = task.fileName;
 if (circle) circle.setAttribute('stroke', '#0d6efd');
 });
 uploader.on('taskProgress', function(task) {
 var pct = clampPercent(task.percent);
 var offset = 264 - (264 * pct / 100);
 if (circle) circle.setAttribute('stroke-dashoffset', offset);
 if (percentText) percentText.textContent = pct + '%';
 if (speed) speed.textContent = AjaxUploader.formatSize(task.speed) + '/s';
 if (uploaded) uploaded.textContent = AjaxUploader.formatSize(task.loaded) + ' / ' + AjaxUploader.formatSize(task.total);
 if (task.speed > 0) {
 if (eta) eta.textContent = AjaxUploader.formatTime((task.total - task.loaded) / task.speed);
 }
 });
 uploader.on('taskComplete', function(task) {
 if (circle) {
 circle.setAttribute('stroke-dashoffset', '0');
 circle.setAttribute('stroke', '#198754');
 }
 if (percentText) percentText.textContent = '100%';
 if (speed) speed.textContent = 'Done';
 if (eta) eta.textContent = '--';
 });
 }
</script>
</asp:Content>
