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
- Finish Loading the page
- Download a gridview as an Excel file in the page
- Call this method
download() - Close the browser
How can I accomplish this?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
}
Method 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.
});
Method 3
You can do it in DOM javascript:
window.onload = function() {
download()
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0