3

I have a button that is generating a PDF file on the server and then setting the response header information to the client for the file to be downloaded.

I would like to display a "Please Wait..." message during the postback because it could be time intensive. I'm able to display a div with no problem when the button is clicked but I'm not able to hide this div when the server returns the information.

Below is my server side code:

Response.Buffer = true;
Response.Charset = "";
Response.AddHeader("content-disposition", "attachment; filename=" + Casefile.SerialCode + ".ppt");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(binaryData);
Response.Flush();
Response.End();

I've tried the following Jquery to hide my Div but it never gets called...

$(document).onLoad(function ()
{
   $('#divLoading').css("display", "none");
});

2 Answers 2

2

I do the exact same thing with this:

        $(document).ready(function () {
            $('#inProgress').hide();
        });

EDIT You can try using the clientscriptmanager on your server side.

ClientScriptManager.RegisterStartupScript(this.GetType(), "HideDiv", "$('#inProgress').hide();", true)

alternatively you can try something like:(in your javascript)

        Sys.Application.add_init(appl_init);

        function appl_init() {
            var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();               
            pgRegMgr.add_endRequest(EndHandler);
        }

        function EndHandler() {           
            $('#inProgress').hide();
        }
Sign up to request clarification or add additional context in comments.

5 Comments

This didn't work for the postback when I changed the response header (but it did on normal postbacks as expected). Any idea why it doesn't get called when using the C# code reference above?
I tried both of the options you added above, neither one gets called after my event. I even checked to see if the page contained the code from the ClientScript.RegisterStartupScript and it was no where to be found.
Interesting, I use both of these methods as well. It seems you are rewriting the response on a current page. I usually have a seperate page specifically used for rewriting the response to some other file type. I like doing this because it removes any other "oddities" that you may be doing on the page. I will try to get you a sample written.
Also 1 more thing. is your postback async or sync? pgRegMgr.add_endRequest will only work on asyc, where pgRegMgr.add_pageLoaded will work on both async and sync.
I'm trying to move all of the logic to a separate page at the moment. At the moment, everything is a full postback (no callbacks). Just a regular asp.net button
0

Try:

pageLoad = function()
{
    $('#divLoading').hide();
};

EDIT: The reason why I went with pageLoad instead of $(document).ready is because pageLoad will fire on partial postbacks (UpdatePanels). From your code it looks like you're doing a full postback but the code should still work.

1 Comment

This didn't work for the postback when I changed the response header (but it did on normal postbacks as expected). Any idea why it doesn't get called when using the C# code reference above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.