At our company, I need to keep a web page up with a list of open orders for our employees.
In the code behind, I filter the search based on what items are selected from a DropDown list ddlList1 and a TextBox txtSearch, sort of like this:
string sql
if (!String.IsNullOrEmpty(ddlList1.SelectedValue) &&
!String.IsNullOrEmpty(txtSearch.Text)) {
sql = string.Format("{0}={1}", ddlList1.SelectedValue, txtSearch.Text);
} else {
sql = null;
}
GridView1.DataSource = db.Select(sql);
GridView1.DataBind();
Management wants this data to be up to date, and never over 10 minutes old.
I am not sure how to do this. Most of my code is done on Windows Forms.
So far, I have found a way to refresh the page using the META tag:
<meta http-equiv="refresh" content="600;Summary.aspx" />
However, it almost appears as though WC3 recommends against using the refresh property:
Note: The value “refresh” should be used carefully, as it takes the control of a page away from the user. Using “refresh” will cause a failure in W3C’s Web Content Accessibility Guidelines.
Ref: HTML meta http-equiv
So, what is the recommended way to refresh my data?
If it helps, our Server is an older SQL 2000 machine.
[Note: I found this question on SO where someone suggested using an AJAX UpdatePanel. My Project, at this time, has no AJAX controls in it. Could I avoid the complexity of AJAX (downloading the latest package, install it into VS2010, add it to my Project’s list of references, then reference AJAX in every page that uses it) or just bite the bullet?]
If you don’t really do much of anything else on this page, you might as well just leave the auto refresh on. Yes, it’s annoying and I hate it and I think it shouldn’t exist, but I won’t have to use the site and if that’s really what the clients want, that’s what the client gets.
You can also use javascript or asp controls to force a refresh other than just through the HTTP meta tag, but it comes with exactly the same problems.
If you go the route of using update panels you have a few advantages. First, and possibly most importantly, if you have much content on the page other than just the gridview being updated you aren’t rendering it repeatedly. This could (potentially) be a significant reduction in server load based on what your whole page looks like, or it could be minimal. Next, you have a more subtle (and also customize-able) visual impact of the update for the user. If they want the site to just flicker and be up to date, an update panel will do that without a cursor change, spinners all over, etc. (You can also add stuff like that back in if you want it to be apparent to the users when the update panel is posting back.)