How to update every second from db? - asp.net

I have to build a site like an auction-site:
I Have a detail page from items where a countdown should run down.
In this page nearly every second a update must be possible without a postback for the user:
coundown must be reset
money of aucton must be updated
gridView with last bidders must be updated
What kind of timer should I use for the countdown?
How can I update every second from DB? ( Ajax? )
How can I update the values / gridView?

You can use an UpdatePanel with Ajax.
However, given the nature of "Internet weather," one second per update is pretty aggressive for that approach.
You might instead consider using Silverlight. You would have much more control that way, and could minimize the amount of data that needs to go over the wire. In fact, you could use long polling with raw TCP connections, to further increase scalability.

For the countdown, you can use the JavaScript timing events. To access the database, if you don't want postback then you indeed need to access the data service by using Ajax. To make things easier, I recommend that you take a look at any Javascript libary such as JQuery.

For the timer I would use Threading.Timer so this can count down uninterrupted in a separate thread. You could also use a TimerCallback delegate which would do the database processing. However, I would be wary about trying to query the database at such a rate.
I would advise you look at using Ajax Update Panel for updating the countdown section of the page alone so you don't have to refresh the entire page.

Related

refresh grid without page post back, please advise

I am doing some grid work just like a stock exchange application which will have good data volume and page should be automatically refresh after some mentioned time say 1 min or 30 sec without being post back.
What is best way to do this ? Should I use grid with ajax or grid with ajax and web service should be used ? If possible please refer me some article or link on implementation of your suggestion.
You can use an UpdatePanel (place the grid inside the panel) and maybe have a JavaScript timer to update the panel periodically.
Alternatively you can have a straight HTML table and periodically call a webservice and update the table from the client side. I think you would get slightly better performance but there is a bit more work involved.
A webservice call from JavaScript will not cause a postback. When calling a webservice you might get better performance because you are only getting data instead of formatted HTML. However, you will probably return the data in XML or Json format, so there will be an overhead (Json will be better in that respect).
If you know that only a small portion of values are going to change between two refreshes, then you will get better performance by only returning the values that have changed.
If you're not very experienced with JavaScript then I would suggest that you use a library such as jQuery. You may read the following resources for implementation details:
Calling an ASP.NET webservice with jQuery
Updating an HTML table from Json data using jQuery
Depending how experienced you are with webservices, Json and jQuery, it may not be an easy task. The UpdatePanel option is definitely easier to implement.

Json, Timer, Ajax, What is faster (for shared Chronometer)?

I'm developing an application using ASP.Net.
For first the idea: "My WebApp needs an chronometerto be shared by users and all users will se the same value in cronometer. When a user clicks on a button, the cronometer needs to be restarted and all users will need to see that!"
All right, now I'd like to know what's the best choose to improve more performace an make sure that all users will see the same value in chronometer?
Need I use JSon (with jquery in client side), Timer with UpdatePanel of Ajax Extensions, pure Ajax (with JQuery) or any idea to suggested ? Any suggestion for how to shared a cronometer for all users in C# (put information in Cache or database) ?
Thanks all
Cheers
It is impossible for all users to see the same value in the chronometer. JQuery will be faster than an UpdatePanel (an UpdatePanel needs to post the whole page back to the server), but still some kind of polling to the server is needed. You could set the polling period to 1 second - in that case the difference in users' chronometers will be at the most 1 second. Even that value however is too low for a repeating Ajax request and could easily hog browser's resources.

A big dilemma - ASP.NET and jQuery

I have a wizard style interface where I need to collect data from users. I've been asked by my managers that the information is to be collected in a step by step type process.
I've decided to have a page.aspx with each step of the process as a separate user control. step1.ascx step2.ascx etc...
The way it works now, is that when the initial GET request comes in, I render the entire page (which sits inside of a master page) and step1.ascx. When then next POST request comes in for step 2 (using query string step=2), I render only step2.ascx to the browser by overriding the Render(HtmlTextWriter) method and use jQuery html() method to replace the contents of a div.
The problem with this whole approach, besides being hacky (in my opinion) is that it's impossible to update viewstate as this is usually handled server side.
My workaround is to store the contents of step1.ascx into temporary session storage so if the user decides to click the Back button to go back one step, I can spit out the values that were stored for it previously.
I feel I'm putting on my techy hat on here in wanting to try the latest Javascript craze as jQuery with .NET has taken a lot of hack like approaches and reverse engineering to get right. Would it be easier to simply use an updatepanel and be done with it or is there a site with a comprehensive resource of using jQuery to do everything in ASP.NET?
Thanks for taking the time to read this.
Another approach, that might be easier to work with, is to load the entire form with the initial GET request, and then hide all sections except the first one. You then use jQuery to hide and show different parts of the form, and when the final section is shown the entire form is posted in one POST to the server. That way you can handle the input on the server just as if the data entry was done in one step by the user, and still get the step-by-step expreience on the client side.
You could just place all your user controls one after another and turn on the visibility of the current step's control and turn on other controls when appropriate . No need to mess with overriding Render(). This way the user controls' viewstate will be managed by the server. and you can focus on any step validation logic.
Using an UpdatePanel to contain the steps would give the ajax experience and still be able to provide validation on each step. If you are OK with validating multiple steps at once, Tomas Lycken's suggestion (hide/show with JQuery), would give a fast step by step experience.
Did you look into using the ASP.NET Wizard control? It's a bit of a challenge to customize the UI, but otherwise it's worked well for me in similar scenarios.

Continuously update an ASP.NET page using AJAX

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:
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).
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.
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.
And ASP.NET in general but times are tough.
Personally, I think UpdatePanel is too heavy. You could use jQuery along with an ASP.NET Web service function that outputs JSON.
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.

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.

Resources