You can prevent portions of your code from executing during a partial-page update like this:
if (! ScriptManager.IsInAsyncPostBack) {
// Code in here won't happen during UpdatePanel actions
}
UpdatePanels execute most of the ASP.NET page lifecycle by design. If you abort that process (via Response.End()
for example), the request doesn't complete, so the client won't get the data it needs to update the page's HTML.
When you trigger a server-side method in an UpdatePanel ASP.NET does the following:
- Rebuilds the portion of the page within the panel from scratch by running through the normal ASP.NET page lifecycle (well, slightly abridged, but close).
- Sends the panel's HTML back to the client.
- Rebuilds the panel on the client using javascript DOM manipulation.
(For more see my recent answer to this question, and see UpdatePanel Control Overview or this article for details)
There are several alternatives to the UpdatePanel AJAX implementation that don't involve going through the whole page lifecycle. One of the most popular is Using jQuery to directly call ASP.NET AJAX page methods.
Using jQuery for AJAX calls gets you a little closer to the metal (so to speak) than UpdatePanels, but there's tons of good help to get you started - on StackOverflow itself and on Encosia (the source of that last link).