[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-10
5
Medium Priority
?
250 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:jxharding
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36943566
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
 

Author Comment

by:jxharding
ID: 36947023
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
 
LVL 28

Expert Comment

by:strickdd
ID: 36948207
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
 

Author Comment

by:jxharding
ID: 36950621
thanks, any lead/link somewhere on how to do this please?
0
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36951085
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question