Avatar of jxharding
jxharding

asked on 

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

ASP.NET

Avatar of undefined
Last Comment
strickdd
Avatar of strickdd
strickdd
Flag of United States of America image

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

Avatar of jxharding
jxharding

ASKER

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
Avatar of strickdd
strickdd
Flag of United States of America image

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.
Avatar of jxharding
jxharding

ASKER

thanks, any lead/link somewhere on how to do this please?
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo