views:

301

answers:

1

I just wondering how to handle a lot of states using ASP .NET and postbacks.

see the image

I know someone can use:

  • javascript for client script that change <input type="text" style="display:none"/> controls for passing javascript variables to ASP .NET
  • use ClientScript.RegisterStartupScript for calling javascript function after postbacks
  • reload content for dynamic controls after postback

This introduce a lot of overhead, variables, states, messing and confusing code.

I would normally do it:

  • multiple pages
  • every page being a fully defined state
  • passing QueryString variables thorugh pages
  • giving "Back with one step" option to the user

My project manager won't let me do it in my own style.
No ASP .NET AJAX, they say it make the page too big and its slow.

+2  A: 

First of all, trying to use <input type="text" style="display:none"/> you are reinventing the wheel. Use <input type='hidden' /> instead.
The problem of too big pages is not in a ASP.NET AJAX (but I don't like it anyway) but in the ASP.NET webforms abstraction. Often viewstate becomes too large (60-70% of the page weight or more) and this is really bad. Also when you have only one form with a lot of editing controls in it all values of inputs (html inputs, in asp.net - textboxes, checkboxes and so on) will be sent back to the server on each postback. In my opinion this is bad, really bad. The solution is not to use webforms. You can try out ASP.NET MVC. Using it you easily can control all you need and there are no headache with viewstates, controlstates, page and control lifecycle, stupid ctl0$ctlSomeValue$ctlAnotherParam$MyCoolTextBox identifiers (this will be changed in ASP.NET 4). I made my choice - no more webforms, hello, mvc!
About your situation. You can create a webservice (some RESTful or something like this) which will provide all methods to add/edit/move/delete items. And create a page which will use this service to add/create/move/delete items. This requires a good knowledge of JS or at least a big wish to learn it. I prefer this approach, there will be only small requests to do some actions on the page so user will be happy. And information on the page and state of the page will not be broken - all requests to the service will be through AJAX.
Another solution is to manage all these states manually - in hidden fields, query variables and so on. This is veery thicky and hard approach for ASP.NET WebForms. And it will take a lot of time.
So my advice is to move to MVC or to create some UI frontend for a service.
And another stone in the ASP.NET WebForms side - http://blog.stevehorn.cc/2009/05/aspnet-webforms-and-mvc.html

zihotki
Thanks for the answer.It seems that I need to get into ASP .NET MVC, it's a new concept for me, discovered here on SO.
pixel3cs
This concept is new for .Net world, but in Ruby, Python, PHP and Java world this concept is not new.And have a look at SharpArchitecture project, it provides very good base architecture. And AtomSite is very interesting too. :)
zihotki
And one more pros to use it - check out this new post of Scott Hanselman - http://www.hanselman.com/blog/MSDNUpdatesAndRFCForYou.aspx :"The MSDN Forums have been updated and are now written in ASP.NET MVC." =)
zihotki