views:

323

answers:

2

I have an ASP.NET page that is interacting with a business class. I want to continuously update controls on my page based on user entered values, e.g. update totals. The calculations are embedded in business logic but they're simple enough to reproduce elsewhere. I've thought of three ways to accomplish this:

  1. Dynamically update the page using JavaScript. I don't want to do this because I don't want to risk floating point math problems where the values on the page don't match the values calculated by the business class (those properties are decimals).
  2. Clear calculated fields on changes and force the user to click a re-calculate button. This is a poor user experience and wiring up JavaScript to ASP.NET controls is tedious.
  3. Use an AJAX UpdatePanel, set data entry controls to autopostback, and handle the "changed" event for the control, e.g. TextChanged for TextBox.

The third method seems cleanest to me, provides a nice user experience, and allows me to interact directly with my business class that I've stored in session state.

My question is: Is this a good idea and/or a common practice? Are there better ways to accomplish this?

I haven't done ASP.NET work for a few years and I have a prejudice against autopostback[1]. I've looked at the size of the request and it's currently negligible at 1.5kB. The site will be low use but we may have a small number of users with dial-up connections.

  1. And ASP.NET in general but times are tough.
+5  A: 

Personally, I think UpdatePanel is too heavy. You could use jQuery along with an ASP.NET Web service function that outputs JSON.

Mehrdad Afshari
a straight ashx w/ jayrock, asp.net mvc with a jsonresult and a wcf service all are decent options in this line.
Tracker1
These are good responses but I don't have time to learn several new technologies for this project.
Jamie Ide
A: 

You're correct in thinking the third option is your best. This is the kind of thing that AJAX is made for. Go for it.

Justin Niessner