首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含流程完成消息的流程栏

包含流程完成消息的流程栏
EN

Stack Overflow用户
提问于 2014-08-13 07:04:20
回答 2查看 58关注 0票数 0

我要在按钮上执行多个存储过程,单击我的.aspx页面上的事件,每次过程执行时,我必须在Process上显示一条消息

流程1已经完成。过程2已经完成。过程3已经完成。

请帮忙

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-13 08:46:35

一种方法是结合Ajax计时器使用Update。

下面这篇文章可能会很有用。

http://msdn.microsoft.com/en-in/library/cc295400.aspx

本文中给出的示例向您展示了如何用计时器事件的当前服务器时间更新update中的标签。您可以轻松地调整代码以满足您的需要,并显示您想要显示的任何消息,而不是服务器时间。

编辑

按照要求,这里有一些示例代码。

  1. 向应用程序中添加一个新的aspx文件并将其命名为Test2.aspx
  2. 替换aspx文件的内容,如下所示。
  3. 运行应用程序并查看示例代码是否正常工作。
  4. 自定义DoWorkAsync方法以满足您的需要。
  5. 运行应用程序并测试修改过的代码。

ASPX文件:

代码语言:javascript
复制
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test2.aspx.vb" Inherits="Test2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Asynchronous Update Demo</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    </asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>
            <asp:Timer runat="server" ID="Timer1" Interval="1000" />
            <asp:Button ID="Button1" runat="server" Text="Start" /><br />
            <asp:Label runat="server" Text="Click Start button to being processing." ID="Label1" />
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

文件后面的代码:

(注意内联评论)

代码语言:javascript
复制
Partial Class Test2
    Inherits System.Web.UI.Page

    Private MyAsyncProcessor As AsyncProcessor

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("MyAsyncProcessor") IsNot Nothing Then
            ' we are still processing.. so extract the reference of our class back from session variable
            Me.MyAsyncProcessor = Session("MyAsyncProcessor")
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' this event is fired everytime a timer ticks. 
        If MyAsyncProcessor IsNot Nothing Then
            Label1.Text = MyAsyncProcessor.StatusMessage
            If Not MyAsyncProcessor.IsProcessing Then
                MyAsyncProcessor = Nothing
                Session.Remove("MyAsyncProcessor")
                Timer1.Enabled = False
            End If
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = ""
        Button1.Enabled = False
        Timer1.Enabled = True
        MyAsyncProcessor = New AsyncProcessor
        MyAsyncProcessor.Start()
        Session("MyAsyncProcessor") = MyAsyncProcessor  'save reference in a session variable
    End Sub
End Class

Public Class AsyncProcessor
    Public IsProcessing As Boolean
    Public StatusMessage As String

    Public Sub Start()
        Dim th As New Threading.Thread(AddressOf DoWorkAsync)
        th.Start()
    End Sub

    Private Sub DoWorkAsync()
        ' *** Replace this code with whatever work you want to do ***
        ' Set IsProcessing=True at beginnning of task and set it to False when exitting.
        ' Update the StatusMessage at regular intervals.

        IsProcessing = True
        For i = 1 To 10
            '' this sleep is only to simulate a long going task
            Threading.Thread.Sleep(1000)
            StatusMessage &= String.Format("Task #{0} completed... <br>", i)
        Next
        StatusMessage &= "All tasks completed."
        IsProcessing = False
    End Sub
End Class
票数 0
EN

Stack Overflow用户

发布于 2014-08-13 09:10:05

另一种方法是将工作委托给iframe中的页面。在iframe页面上,当您的代码被处理时,您可以更新一个会话变量以包含“已完成的处理第一步”(或其他任何内容),并使用父页面上的PageMethods调用一个Web方法,该方法获取由iframe中页面上的代码更新的会话的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25280053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档