我有一个文件夹,里面有很多PDF文件。当用户从DropDownList中选择类别并单击按钮时,系统会将文件(不是全部)复制到一个新文件夹中,然后生成压缩文件。
这些步骤都没问题,但问题是生成的zip服务什么时候结束。
我要写一个例子:
<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="Server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Services>
<asp:ServiceReference Path="SomeService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManagerProxy>
<script type="text/javascript">
function copyFiles(id) {
SomeService.CopyFiles($ja("#DropDownList1").val(), id, FuncionSucceeded, FuncionFailed);
}
function FuncionSucceeded(result, eventArgs) {
document.getElementById("GenerateZip").click();
}
function FuncionFailed(result, eventArgs) {
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Generate Zip" />
<asp:Timer ID="Timer1" runat="server" Interval="5000" Enabled="false">
</asp:Timer>
<asp:Button ID="btnGenerateZip" runat="server" Style="display: none;" ClientIDMode="Static" />
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/loading.gif"
Visible="False" />
<asp:Label ID="Label1" runat="server" Text="" Visible="false"></asp:Label>
<asp:LinkButton runat="server" Visible="false" ID="linkzip" Text="Descargar" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>和代码:
'This code call the client side to copy the files
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
If DropDownList1.SelectedValue = "0" Then
Exit Sub
End If
Dim pathName As String = "The path here"
If Not File.Exists(pathName) Then
Dim folder As String = Path.GetDirectoryName(pathName)
If Not Directory.Exists(folder) Then
Directory.CreateDirectory(folder)
End If
End If
Image1.Visible = True
Label1.Visible = True
Timer1.Enabled = True
Label1.Text = "Generating zip"
Dim script As String = "copyFiles('1234');"
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType(), Guid.NewGuid().ToString(), script, True)
End Sub
'When the client side returns the function `FunctionSucceeded` call next function
Private Sub btnGenerateZip_Click(sender As Object, e As EventArgs) Handles btnGenerarZip.Click
GenerateZip()
End Sub
Private Sub GenerateZip()
Try
Dim ws As New AnotherService.ServiceExample
Dim ar2 As New AsyncCallback(AddressOf DownloadFile)
Dim pathName As String = String.Format("{0}", path)
result = ws.BeginSomeFunction(path, ar2, ws)
Catch ex As Exception
generaZip = False
End Try
End Sub和回调函数:
Protected Sub DownloadFile(ar As IAsyncResult)
Dim ws As New AnotherService.ServiceExample
Try
Dim pathName As String ="Path"
ws.deleteFolder(pathName)
ws.EndSomeFunction(ar)
Image1.Visible = False
Label1.Text = "OK"
Timer1.Enabled = Image1.Visible
linkzip.Visible = True
generaZip = True
Catch ex As Exception
generaZip = False
End Try
End Sub和定时器滴答:
Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
Select Case generaZip
Case True
Image1.Visible = False
Label1.Text = "Everything is ok"
Timer1.Enabled = Image1.Visible
linkzip.Visible = True
Case False
Image1.Visible = False
Label1.Text = "Error"
Timer1.Enabled = Image1.Visible
End Select
End Sub问题是,当我们在DownloadFile函数(异步回调函数)中时,我在那里所做的任何事情都不起作用。我更改了许多属性、值、变量值,当tick函数触发时,就像我什么也没做一样。
我已经更改了所有这些行:
Image1.Visible = False
Label1.Text = "OK."
Timer1.Enabled = Image1.Visible
linkzip.Visible = True
generaZip = Truehttps://stackoverflow.com/questions/44502496
复制相似问题