【发布时间】:2015-07-24 20:55:12
【问题描述】:
我正在用 ASP.Net 编写网页。目前,我有一个asp:Table,用作处理输出的一种“日志”。这个想法是用户选择几个文件并单击一个按钮,每个文件都被“处理”,日志显示正在发生的事情。处理异步进行。
这里是相关的处理段:
Protected Sub DoAsyncWork()
Dim count = 0
For Each row As GridViewRow In gvList.Rows
count = count + 1
If CType(row.FindControl("cbImport"), System.Web.UI.WebControls.CheckBox).Checked Then
push_to_log("")
push_to_log("Updating Active Projects +" + HttpUtility.HtmlDecode(row.Cells(1).Text).ToString.Substring(0, 30) + "...")
Dim xp(3) As Object
xp(0) = HttpUtility.HtmlDecode(row.Cells(0).Text)
xp(1) = HttpUtility.HtmlDecode(row.Cells(1).Text)
xp(2) = HttpUtility.HtmlDecode(row.Cells(2).Text)
xp(3) = 0
'oDC.UpdateData("Import_P3e_Project ", xp)
If (xp(3) <> 0) Then
push_to_log("Success: " + xp(3).ToString + " have been updated")
Else
push_to_log("Failure: " + xp(3).ToString + " activities updated")
End If
End If
Next
push_to_log("")
push_to_log("Import Complete!")
End Sub
这就是我调用进程工作者函数的方式:
Protected Sub button_Import(sender As Object, e As EventArgs) Handles btnImport.Click
Dim t As New Thread(New ThreadStart(AddressOf DoAsyncWork))
t.Priority = Threading.ThreadPriority.Normal
t.Start()
push_to_log("Start Import")
End Sub
我将内容附加到日志的方式是动态创建行和单元格,然后将它们添加到我的表中。下面是相关的子程序:
Protected Sub push_to_log(ByVal str As String)
Dim newRow As TableRow = New TableRow
Dim newCell As TableCell = New TableCell
logArrayList.Add(str)
Me.ViewState.Add("arrayListInViewState", logArrayList)
newCell.Text = str
newCell.Style("Color") = "White"
newCell.ID = "cell" + (logArrayList.Count - 1).ToString
newRow.ID = "row" + (logArrayList.Count - 1).ToString
newRow.Cells.Add(newCell)
logTable.Rows.Add(newRow)
HiddenButton_Click(HiddenButton, New EventArgs())
'UpdateLogPanel.Update()
'UpdateLogPanel.Focus()
End Sub
通过使用 ViewState 存储我的数据数组列表并在回发时重新创建日志,我已经正确地保留了日志。我的日志的相关标记如下所示:
<asp:UpdatePanel ID="UpdateLogPanel" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="HiddenButton" />
</Triggers>
<ContentTemplate>
<div ID="Div1" class="DefinitionPanel" style="text-align:left;height:200px;overflow:hidden;" runat="server">
<span style="display:inline-block; width:100px;"></span>
<div class="scrollingtable">
<div>
<div id="viewContainer">
<asp:table id="logTable" runat="server" enableviewstate="false">
</asp:table>
</div>
</div>
</div>
</div>
<asp:Button ID="HiddenButton" runat="server" style="display:none;" />
</ContentTemplate>
</asp:UpdatePanel>
我正在尝试让我的asp:Table 每次发布消息时更新。我认为启用部分回发并使用UpdatePanel 将是正确的解决方案,但在整个过程完成之前,我的日志仍然没有输出任何内容。
在我的asp:Table/log 中添加消息后,我尝试调用
UpdateLogPanel.Update()
这似乎没有什么不同。最后我尝试添加asp:AsyncPostBackTrigger 和隐藏按钮,希望它能解决问题,但似乎没有。以下是hiddenButton 事件的样子:
Protected Sub HiddenButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles HiddenButton.Click
UpdateLogPanel.Visible = True
End Sub
任何关于如何在我向其添加消息时使我的日志重新呈现的指导都将受到高度重视。
【问题讨论】:
-
VB6.NET?有趣的。编辑时间...
标签: asp.net vb.net logging updatepanel