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

x
?
Solved

using a httpresponse and calling a javascript function.

Posted on 2012-09-09
9
Medium Priority
?
1,413 Views
Last Modified: 2012-09-16
Hi,

I have the following c# code which exports a pdf I have created ready for saving:
var response = System.Web.HttpContext.Current.Response;
            response.Clear();
            response.AddHeader("Content-Type", "binary/octet-stream");
            response.AddHeader("Content-Disposition", "attachment; filename=Results.pdf; size=" + pdfBytes.Length.ToString());           
            response.Flush();
            response.BinaryWrite(pdfBytes);
            response.Flush();
            response.End();

Open in new window


The next line of code after this then calls a function which does this:
 var script = string.Concat("<script type=\"text/javascript\"> \r\n",
                                          "  $(document).ready(function () { \r\n",
                                          "    SpinnerOff(); \r\n",
                                          "  }); \r\n",

                                          "</script>");
            ClientScript.RegisterClientScriptBlock(GetType(), "SpinnerOff", script);

Open in new window


So basically once the pdf has been created I want to turn off a spinner that I turned when the button was first clicked as the pdf's can take a bit of time to be produced.

The javascript call isn't happening though.

Any ideas why?

Thanks
0
Comment
Question by:scm0sml
  • 5
  • 3
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38381739
I see where you are registering the Javascript block, but not where it is being called.
0
 

Author Comment

by:scm0sml
ID: 38382142
Basically just before this line:
var response = System.Web.HttpContext.Current.Response;

I have:
CloseSpinner();

That method just contains the javascript code so....
private void CloseSpinner()
        {           
            var script = string.Concat("<script type=\"text/javascript\"> \r\n",
                                          "  $(document).ready(function () { \r\n",
                                          "    SpinnerOff(); \r\n",
                                          "  }); \r\n",

                                          "</script>");
            ClientScript.RegisterClientScriptBlock(GetType(), "SpinnerOff", script);
        }

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38384466
That registers the script block, but I don't believe that it calls it.  Generally, you have to attach a call to an HTML element, such as a button, body onLoad, etc.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:scm0sml
ID: 38384484
Its what I normally use to call my javascript alert, works fine normally.

Its just having the two happening at the same time seems to be causing an issue....
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38385199
My mind is stuck in the MVC 3 world, where these types of things are approached differently.  

Are you able to debug this?
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 38385528
there is no need to use $(document).ready(function () { }

you can call directly  SpinnerOff();

var script = string.Concat("<script type=\"text/javascript\"> \r\n",
                                          "    SpinnerOff(); \r\n",
                                          "</script>");
            ClientScript.RegisterClientScriptBlock(GetType(), "SpinnerOff", script);
0
 

Author Comment

by:scm0sml
ID: 38385761
still not solving the problem though.
0
 

Accepted Solution

by:
scm0sml earned 0 total points
ID: 38386158
0
 

Author Closing Comment

by:scm0sml
ID: 38402857
did't get a working solution until I found one myself.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

872 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