What's the difference between onload () and Onshow () in small program development? - wechat

If you want to refresh every time you enter this page, should you choose Onshow ()?

The docs desciptions:
OnLoad is running which your Page first load.
OnShow is running which your Page scripts loaded which includes your Page first load ,back to the Page from other Pages ,back form calling or back from other apps and miniprograms

Related

simultaneous page load and ajax call

I have a web application with some pages take quite a long time to load because of what they have to do in code behind. I would like to show what is going on to the user by showing the different status of the process.
I was thinking about calling recursively (by ajax) a page which ready a value in the session. This value is set by the page that take time to load.
The problem is that the page called by ajax is not executed while the other page load is finished.
Is there some way to do that?
Thanks advance
The usual pattern here is to load an initial status page that triggers an AJAX call to retrieve the final version of the page, overwriting the original with the result of your AJAX call when it completes.
Separate the part of the code that takes a long time and call it asynchronously (e.g. as a WebMethod) on page load, e.g. if using jQuery, on document.ready. You could also fake this using an UpdatePanel which is set to conditional refresh, and the code is never run by default. Then refresh it from script using __doPostBack('updatePanelUniqueID','').

Redirection from a Telerik Rad Window

In an asp.net web application, I have a modal popup built with a Telerik Rad Window. In that popup there is a button which must do some action in its "code-behind" and then redirect the application to another page.
For the redirection I use the javascript command 'top.document.location.href = myPage' (sent to the browser from the code-behind with a ScriptManager.RegisterClientScriptBlock(...)).
This solves my problem but it is not very nice. When the button is pressed, this triggers the post-back. In the browser the popup is covered by a RadLoadingPanel which disapper when the post-back is finished. Then during a few seconds, nothing happens in the application and it is only after some time that the browser loads the new page.
The fact that nothing happens during a few second is not great since a user cannot know what the application is doing.
What can I do ? Is there a better way to do the redirection ? (I'm very new to javascript programming...).
Instead of just calling 'top.document.location.href = myPage', you can call a function that displays an overlay (e.g. show a RadAjaxLoadingPanel over the parent page body) and then set the new URL. See http://www.telerik.com/help/aspnet-ajax/ajxshowhideloadingpanel.html for info on how to show loading panels with JavaScript.
I think the delay after you set location.href is normal - the browser/server take some time to retrieve the new page HTML so the old page cannot go away instantly.

Javascript object not initialized on slow connections

Here's the odd situation:
we have a piece of javascript library that is being called on our onload of aspx page.
It works everytime for us, but the clients that have low speed modems get an error, because the object is not getting initialized and the aspx page is already loaded.!!
Is there any suggestions on how to call this piece of js code?
Thanks,
make sure you have your end tags.. i have seen onLoads in the not working right when your core tags are incomplete or not properly formatted
The onload even happens when everything in the page is loaded. If you have some script that is loading from a different server (ads, statistics), the onload event won't fire until those are loaded also. If their server is having problems, your onload may never fire at all, or after several minutes when the browser gives up waiting.
Instead of using onload you could put your code in a script tag as early as possible in the page, i.e. after the last element that the script needs.
If you have some external script that doesn't need a specific place in the page (statistics for example), you can move it to the bottom of the page to minimise the risk of interference with the rest of the page.
With JQuery you can call your functions with ready event :
$(document).ready(function() {
// call your functions here
});
The event will be called when the DOM is loaded.

asp.net make button show different view of MultiView AND download a file

I have a page on my site on which users have to fill out details before they can download a document. The user details section is on the first view in a MultiView control.
After filling out their details I'd like the user to click a button which will show them a file download prompt (I've done this successfully with an ashx handler) then redirect them to the second view page of the MultiView which will say "thank you for downloading" or something like that.
I've tried the usual Response.Redirect("~/DownloadHandler.ashx"); within the button click event handler, but obviously this prevents the page completing the postback and showing the last page of the MultiView.
Is there a way around this, or should I just change my UI to accommodate this?
EDIT:
I've concluded that it's better to just provide a hyperlink to the document (on my confirmation page, and change the wording accordingly) as this provides a consistent user experience independent of the browser they're using.
Go ahead and take them to the second view of the MultiView. Add a javascript method that will download the document, and trigger it from your codebehind.1 E.g.,
In your page:
<script>
function downloadFile(url) {
window.location = url;
//you could also try window.open(url, 'Download')
}
</script>
In your code behind:
script = string.Format("downloadFile('{0}');", "DownloadHandler.ashx");
Page.ClientScriptManager.RegisterStartupScript(typeof(Page), "download", script, true);
You could also add a delay (using setTimeout) before the file is downloaded.
More info:
Initiating a file download that works well, even in IE?

Change processing page while loading data is asp.net

How do I show a processing page on load of a certain data display page in asp.net?
I still like the classic 2 page solution. The first page has an BODY ONLOAD call that does "window.location = 'Page2.asp';". This results in the first page being displayed and the 2 page being invoked. While the second page is doing it's work the first page remains displayed.
There are a couple of "problems" with this solution:
User clicking refreshing will not take them to the first page (they are on the second page, and clicking refresh will start the second page loading again).
This relies on the second page sending its results all at once (basically "buffered", which is the default).
You could also do this with AJAX (all on one page):
Display a waiting message
Initiate the work with an AJAX load request
Once the load is complete rebuild the page or head of to a "completed" page.
AJAX is nice, except that it may hide any server side errors that occur (i.e. if the page crashes horribly). Also it depends on how you prefer to do ajax (jQuery vs ASP.NET Ajax vs X Y Z).

Resources