English 中文(简体)
Real time price x quantity calculator
原标题:

I m using ASP.NET and a Repeater control to display my data. The data I have is in stored in a List. How would I implement a simple calculator that is affected in real time? Would I have to use AJAX, or is it possible to do it client-side? I d like the user to be able to change the quantity, with the new price being visible immediately. Seeing as there s a lack of persistence, is there way to prevent constant round-trips to the database to get the price of an item? Thanks

最佳回答

If possible, you can place the price of the item in hidden fields next to the quantity input. Then use simple javascript to calculate the total. Otherwise you can use DynamicPopulate to populate the total using AJAX. But that is still going to get you round trips. You could also do your own ajax which would cache the prices coming back. But that seems the same as placing them in hidden inputs.

问题回答

You could do this client side with JavaScript or server side via AJAX or through a postback, it just depends how fluid you want the UI to be. What kind of calculations will you need to do, simply monetary 2 decimal values? I d be tempted to go for a JavaScript solution with a server side postback fallback solution

To prevent a round trip to the server, you ll need some way of supplying the price value on the client side, whether visible or hidden to the client.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签