我有一个运行一系列任务的流程,每个任务都会更新一个文本框,但我的问题是屏幕在所有任务完成之前都没有加载,我需要在它们发生时看到它们。在我的VBA旧语言中,这可能是DoEvents
或Me.Repaint
。我做错了什么导致我的文本框没有显示每次发送内容时发送给它的内容?
这是在ASP.net和C#中。这是aspx页面: -
<%@ Page Title="ASC Open" Language="C#" AutoEventWireup="true" CodeBehind="ASC_OSC.aspx.cs" Inherits="HICS.ASC_OSC" %>
<head runat="server">
<title>HICS</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
<webopt:BundleReference runat="server" Path="~/Content/css" />
</head>
<body style="padding-top: 5px">
<form id="main" runat="server">
<div class="container-fluid" style="padding-top: 0px">
<h1>Open Access Supply Chain</h1>
<hr />
<div class="container-fluid">
<div ID="ContRow" class="row">
<div class="col-md-12">
<asp:TextBox ID="TxtStatus" runat="server" Height="80%" Width="80%" ReadOnly="true" Wrap="true" AutoPostBack="false" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
</div>
</div>
</form>
</body>
这是C#的片段(并非全部显示,因为它具有代表性),我现在关注的是TxtStatus
。
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace HICS
{
public partial class ASC_OSC : Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlDataReader RS;
int IntPort;
int IntEnvironment;
bool BlnOK;
string StrEnvironmentName;
string StrEnvironmentDB;
Database DB_ASC = new Database();
if (!IsPostBack)
{
BlnOK = true;
TxtStatus.Text += "Getting Port: ";
string StrReturn = home.Procs.UserSetting("ASC_Port");
if (StrReturn == "" || StrReturn == "0")
{
RS = home.DB_HICS.GetRS("SELECT MAX([ASC_Port]) FROM [Tb_Users]");
RS.Read();
IntPort = (RS.GetInt32(0) < 4444)? 4444 : RS.GetInt32(0) + 1;
home.Procs.UserSetting("ASC_Port", IntPort.ToString());
RS.Close();
}
else
{
IntPort = Convert.ToInt32(StrReturn);
}
TxtStatus.Text += String.Concat(IntPort.ToString() , Environment.NewLine);
TxtStatus.Text += "Getting Environment: ";
IntEnvironment = 0;
StrReturn = home.Procs.UserSetting("ASC_Environment");
if (StrReturn == "" || StrReturn == "0")
{
RS = home.DB_HICS.GetRS("SELECT MIN([ID]) FROM [Tb_ASC_Environments]");
RS.Read();
if (RS.IsDBNull(0))
{
BlnOK = false;
}
else
{
IntEnvironment = RS.GetInt32(0);
home.Procs.UserSetting("ASC_Environment", IntEnvironment.ToString());
}
RS.Close();
}
else
{
IntEnvironment = Convert.ToInt32(StrReturn);
RS = home.DB_HICS.GetRS("SELECT COUNT([ID]) FROM [Tb_ASC_Environments] WHERE [ID] = " + IntEnvironment);
RS.Read();
if (RS.GetInt32(0)==0)
{
RS.Close();
RS = home.DB_HICS.GetRS("SELECT MIN([ID]) FROM [Tb_ASC_Environments]");
RS.Read();
if (RS.IsDBNull(0))
{
BlnOK = false;
}
else
{
IntEnvironment = RS.GetInt32(0);
home.Procs.UserSetting("ASC_Environment", IntEnvironment.ToString());
}
}
RS.Close();
}
TxtStatus.Text += String.Concat((BlnOK)?IntEnvironment.ToString():"Error", Environment.NewLine);
if (BlnOK)
{
RS = home.DB_HICS.GetRS("SELECT [Name],[Database] FROM [Tb_ASC_Environments] WHERE [ID] = " + IntEnvironment);
RS.Read();
StrEnvironmentName = RS.GetString(0);
StrEnvironmentDB = RS.GetString(1);
TxtStatus.Text += String.Concat("Environment Name: ", StrEnvironmentName, Environment.NewLine);
TxtStatus.Text += String.Concat("Environment Database: ", StrEnvironmentDB, Environment.NewLine);
TxtStatus.Text += "Connecting to ASC Database: ";
}
}
}
}
}
答案 0 :(得分:2)
您需要了解网页与桌面客户端应用程序根本不同,您可以随时DoEvents
和Repaint
使用。 ASP.NET在服务器端执行,因此在提交页面和处理服务器上的事件之间执行完整的往返。
如果您开始长时间运行的任务并希望获取进度信息,则需要使用AJAX。
有关较旧概念的信息,请参阅Introduction to the UpdateProgress Control
或
track the progress of a database save in a “live” progress bar asp.net mvc采用现代方法
...你必须为你的具体情况做出选择。