7

How can I check whether the page has finished loading? When it has, how can I execute a method already created in the C# code behind for that page?

I would like to orchestrate the following sequence of events

  1. Finish Loading the page
  2. Download a gridview as an Excel file in the page
  3. Call this method download()
  4. Close the browser

How can I accomplish this?

Ryan Gates
  • 4,501
  • 6
  • 50
  • 90

3 Answers3

18

Does this link answer your question?

Example usage (in your C# code)

protected void Page_Load(object sender, EventArgs e)
{
      Page.LoadComplete +=new EventHandler(Page_LoadComplete);
}

void  Page_LoadComplete(object sender, EventArgs e)
{
    // call your download function
}
Carl Winder
  • 938
  • 8
  • 18
  • i think so. but i dont know how to use that . confused –  Dec 21 '11 at 09:45
  • thanks for the code. Looks like now there is something wrong with my code, as it still no data inside the downloaded data. (nvr show the nested gridview data) –  Dec 21 '11 at 10:02
  • which is kinda weird though. i thought it should be 'okay' once the page has fully loaded. –  Dec 21 '11 at 10:06
  • I'm sorry that will have to be another question. I've never done anything with Excel :( – Carl Winder Dec 21 '11 at 10:07
  • 3
    You don't need to add an event listener to Page.LoadComplete. Just like Page_Load event, it is being fired by the core. You just need to create the proper method with void Page_LoadComplete(object sender, EventArgs e) { //do something } – Roni Tovi May 05 '18 at 13:03
2

Use JQuery and make a callback to open the xls file.

There is a few solutions detailed here POST to server, receive PDF, deliver to user w/ jQuery

Basically you can hook into the

$(document).ready(function() {
  // do window.location or another one of the options to download the file.
});
Community
  • 1
  • 1
Dave Walker
  • 3,498
  • 1
  • 24
  • 25
  • im quite confused with jquery tho. so yea, its kind of difficult for me without a same scenario code. T.T –  Dec 21 '11 at 09:49
  • seems like this is the way as it must be executed client side? – paulm Oct 07 '14 at 17:18
0

You can do it in DOM javascript:

window.onload = function() {
   download()
 }
StephenKing
  • 36,187
  • 11
  • 83
  • 112
Atom Vayalinkal
  • 2,642
  • 7
  • 29
  • 37