ajax updatpanel : after i export to excel, all rendering stops on page and i cant set a label//hiddenfield value,code included

hi,
simple project
Ajax, Excel Export,
 all i need is a label to be updated to say that the process has finished
(this in turn will help a lot of things e.g. if the user selectes the export button again, the client side
will check that the value of the label is "Updated" and if not, will inform the user that the process is busy etc etc)

can you please help me to figure out how to get a label to update on the front end / clients side, after a response.write/response.end

 
After the Response.End, immediately a {System.Threading.ThreadAbortException} exception is thrown
i then tried to use :     Catch ex As Threading.ThreadAbortException

so whilst the code actually executes Label1.Text = "Updated",
the label still does not get set and the client side does not render.

i even tried it in the load event of the page, i simply cannot get any controls value to be set after the Response.End.

please help

to use this demo, please open a vb.net website, add reference to ajax, add masterpage, this is the code for the default page.
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
       <script language="javascript" type="text/javascript"> 
     function NoProcessesAlreadyRunning()
 {  
    var isBusy = "1";
    
    if (isBusy == 1)
    {
        alert("Currently Processing Report");
        return false;
    }
    else
    {
        isBusy = "1";
        return true;
    }
 }
    </script>
     
<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

        <asp:Panel ID="pnl2Export" runat="server">

        <asp:Table ID="Table1" runat="server">

        <asp:TableRow>

        <asp:TableCell>

        This will Print if this is successful!

        </asp:TableCell>

         

        </asp:TableRow>

        </asp:Table>

        </asp:Panel>

         

        <asp:Button ID="Postback" runat="server" Text="Export Control (panel)" OnClick="Postback_Click" OnClientClick=""/>
</ContentTemplate>

<Triggers>

<asp:PostBackTrigger ControlID="Postback" />

</Triggers>

</asp:UpdatePanel>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    <asp:HiddenField ID="hfBusyProcessing" runat="server" />
    
</asp:Content>

Open in new window

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Postback_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Try
            ' excel export
            Response.Clear()

            Response.AddHeader("content-disposition", "attachment;filename=ExcelReport.xls")

            Response.Charset = ""

            'Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.ContentType = "application/vnd.xls"

            Dim stringWrite As New System.IO.StringWriter()

            Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

            pnl2Export.RenderControl(htmlWrite)

            Response.Write(stringWrite.ToString())

            Response.[End]()
            hfBusyProcessing.Value = "0"


            Label1.Text = "Updated" 'this portion does not execute correctly and the label1.text = ""
        Catch ex As Threading.ThreadAbortException
            Label1.Text = "Updated"
        Catch ex As Exception

        End Try
        Label1.Text = "Updated"

    End Sub
End Class

Open in new window

jxhardingAsked:
Who is Participating?
 
strickddConnect With a Mentor Commented:
var win1;

function download()
{
    win1 = window.open(...);
    check();
}

function check() {
  if (win1.closed) {
    // do whatever you want
  } else setTimeout("check()",1);
}

Open in new window

0
 
strickddCommented:
Move your button outside the UpdatePanel. Since you are performing a Response.METHOD in the server-side code, you cannot use the control inside an update panel - one of the limitations.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

        <asp:Panel ID="pnl2Export" runat="server">

        <asp:Table ID="Table1" runat="server">

        <asp:TableRow>

        <asp:TableCell>

        This will Print if this is successful!

        </asp:TableCell>

         

        </asp:TableRow>

        </asp:Table>

        </asp:Panel>

         

        
</ContentTemplate>

<Triggers>

<asp:PostBackTrigger ControlID="Postback" />

</Triggers>

</asp:UpdatePanel>

<asp:Button ID="Postback" runat="server" Text="Export Control (panel)" OnClick="Postback_Click" OnClientClick=""/>

Open in new window

0
 
jxhardingAuthor Commented:
Hi, i did exactly as indicated
it unfortunately does not update the label , does not seem it is possible to update any client side control after repsonse.End
0
 
strickddCommented:
Correct, once a Response.End is issued, no further processing is done. One thing you can do is to use javascript to open a new window for the download and then you can detect when that window is closed and update the label.
0
 
jxhardingAuthor Commented:
thanks, any lead/link somewhere on how to do this please?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.