HttpResponse之后在ASP.NET上启用按钮

Enable button on ASP.NET after HttpResponse

本文关键字:启用 按钮 NET ASP 之后 HttpResponse      更新时间:2023-09-26

我的ASP.NET页面上有一个按钮,它在点击时调用被禁用(以防止双击),并调用以下函数:

Private Sub ExportToExcel(ByVal nameReport As String, ByVal wControl As GridView, ByVal sTitle As String)
    Dim responsePage As HttpResponse = Response
    Dim sw As New StringWriter()
    Dim htw As New HtmlTextWriter(sw)
    Dim pageToRender As New Page()
    Dim form As New HtmlForm()
    wControl.AllowPaging = False
    wControl.EnableViewState = False
    wControl.DataSource = GetDataSource(False)
    wControl.DataBind()
    wControl.Caption = "<strong>" + sTitle + "</strong>"
    form.Controls.Add(wControl)
    pageToRender.Controls.Add(form)
    responsePage.Clear()
    responsePage.Buffer = True
    responsePage.ContentType = "application/vnd.ms-excel"
    responsePage.AddHeader("Content-Disposition", "attachment;filename=" & nameReport)
    responsePage.Charset = "UTF-8"
    responsePage.ContentEncoding = Encoding.Default
    pageToRender.RenderControl(htw)
    responsePage.Write(sw.ToString())
    responsePage.End()
End Sub

我用来将一些数据导出到Excel。现在,当HttpResponse完成时,我需要重新启用客户端上的按钮。我该怎么做?

Response.End()中止线程并将执行发送到Application_EndRequest。在那之后没有什么可做的了。请查收这篇文章。它提供了一个使用iframe的解决方案。