Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Custom Controls - Alternatives to PostBack?

On my journey into the depths of custom ASP.NET control development I am obviously getting my head around the ASP.NET PostBack model and how it affects control development.

I understand that controls have no "lifetime" in ASP.NET, and therefore must be re-initialized on each and every page load. We overcome this by persisting the objects values/parameters to the ViewState.

Many articles I read therefore suggest not using PostBack since this can add considerable overhead to the Page. I am not looking for how to disable it, I know that.

What I am looking for is:

What alternatives to we have to using the PostBack model to initialize controls?

I know we could use the QueryString, but that seems awfully messy, and obviously unreliable.

Ideally you could give me an overview of the architecture/design of a different approach and the pro's/con's of it..

Many thanks ^_^

like image 435
Rob Cooper Avatar asked Sep 16 '08 19:09

Rob Cooper


1 Answers

Well, Session State is a server-side solution, with its own pile of cruft to deal with if you want to avoid ViewState altogether. Really though, using ViewState in a custom control is all fine and good - just be picky about what you store - only store deltas from the declared control state, don't store anything you're going to get on postback anyway (e.g. from a DB call), etc.

like image 100
Greg Hurlman Avatar answered Oct 20 '22 13:10

Greg Hurlman