Hey All
Developing is more of a hobby at the moment; so apologies if this is a basic question, although after a couple of hours searching the web I can't seem to find an answer. I am currenttly building a support tool for my team which runs a number of SQL queries & BCP processes and returns the results. Some of these actions take quite a while and I would like to update the web UI with status messages. Previously I have been using the Label1.Text = text;
However now I would like to update the Label1.text multiple times while my method is running. Try as I might though it only displays the last update in the method.
I have coded a small test to try get to the bottom of this: -
Web Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Template._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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="progress" runat="server" Text=""></asp:Label><br />
<asp:Image ID="Image1" runat="server" ImageUrl="~/Image/loader.gif"
Visible="False" />
</div>
</form>
</body>
</html>
C# CodeBehind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Template
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
uiUpdate("OUT", 1);
wait();
uiUpdate("In", 0);
}
protected void uiUpdate(string text, Int32 image)
{
if (image == 1)
{
Image1.Visible = true;
}
else
{
Image1.Visible = false;
}
progress.Text = text;
}
protected void wait()
{
DateTime wait;
wait = DateTime.Now + TimeSpan.FromSeconds(10);
while (wait > DateTime.Now)
{
}
}
Is there a way I can get the Label1 & Image to update as the Page_load is running?
Or am I looking at this the totally wrong way (no doubt!)
Thanks