ASP.NET:显示后台进程的状态,以用户 [英] ASP.NET :Show background process status to User

查看:117
本文介绍了ASP.NET:显示后台进程的状态,以用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,在那里将用户输入的一个Excel / CSV文件,并从它和进口读取数据到DB.While插入每个record.I只是想显示有关该记录的详细信息被插入到。用户(例如:A的客户端详细资料...添加)

I have a web page where it will input an excel/CSV file from the user and read the data from it and import to DB.While inserting each record.I just want to show the details about the record being inserted to the user.(Ex : Client Details of A is adding...)

推荐答案

试试这个...输出设置为无缓冲(Response.BufferOutput),并在您的网页一些javascript你看到恰当的更新UI。例如,它可能会更新完成百分比,或者你正在处理的记录的细节SPAN。然后在你的服务器code,输出<脚本>调用从渲染覆盖的JavaScript函数标签。确保你调用flush()在适当的时间,同时也刷新基地code将其渲染后...的JS函数调用应在适当的时候送送下来,执行在客户端上,导致更新页面

Try this... Set the output to unbuffered (Response.BufferOutput), and include some javascript in your page that updates the UI as you see appropriate. For example, it might update a SPAN with a percentage complete or the details of the record you are processing. Then in your server code, output <script> tags that call the Javascript function from the Render override. Make sure you call Flush() at the appropriate times, and also Flush the base code after it Renders... The JS function calls should get sent down at the appropriate times and executed on the client, resulting in an updating page.

例如...您的HTML页面可能是这样的:

For example... Your HTML page might look like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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></title>
    <script type="text/javascript">
        function UpdateScreen(t) {
        	document.getElementById('output').innerHTML = t;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    	<div id='output'></div>
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
    UpdateScreen('hello');
</script>

和您的codebehind会是这样的:

and your codebehind will look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
    	protected void Page_Load(object sender, EventArgs e)
    	{

    	}

    	protected override void Render(HtmlTextWriter writer)
    	{
    		Response.BufferOutput = false;

    		base.Render(writer);
    		Response.Flush();

    		for (int i = 0; i < 10; i++)
    		{
    			Thread.Sleep(1000);
    			Response.Write(string.Format("<script type='text/javascript'>UpdateScreen('{0}');</script>", i * 10));
    			Response.Flush();
    		}
    	}
    }
}

这篇关于ASP.NET:显示后台进程的状态,以用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆