Does every postback in asp.net have to run through entire page cycle?
whether it is partial update or full update, every postback to asp.net server results in running full page life cycle. which means, page_preinit, page_init, page_load functions are run before what actually we want to run what we wanted to show.
Sometimes, we might need to change a small thing, but the slowness of ru开发者_开发技巧nning entire page life cycle sucks.
any help. any technique?
Here's some help:
Don't overload your page lifecycle events with too much code.
Check in your methods if you are in a post back, an async postback, or a regular request so you run only the code you need.
If you are running code you shouldn't be running on each little postback, that's your own mistake. The lifecycle is there to allow you to do what ever you need to do. Don't blame Microsoft if you choose to run unnecessary code.
You can use JavaScript to update only parts of the page on the client, without having to reload the whole page. Here's Microsoft's take on it.
The page event lifecycle is fundamental to the way asp.net forms work, and can't be avoided unless you want to write http handlers for specific urls/requests which would be overkill (using the wrong tool to solve the problem).
However, the asp.net page event cycle is not slow - it is very very fast. Unless you've done something to add code in those events to slow it down. If your post-backs are slow, you need to profile the activity going on or otherwise debug what's going on rather than try to avoid the page life-cycle.
You could move to ASP.net MVC (it can live side-by-side with asp.net webforms). It has a simpler event model to work with. That doesn't mean you can't overload it with extra code via Filters in the same way people load up asp.net page lifecycle events. Moving to asp.net mvc just to solve a performance problem with asp.net page load time is kind of like opening up a new checking account when you can't get the old checking account to balance... it will only give temporary relief :) :)
精彩评论