ASP.NET How To Refresh Data? - c#

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.)

you can use ajax to get the data from server and populate the html container by javascript at client. i don't mean updated panels of microsoft, but xmlhttp.

If you're looking for a simple workaround, try this :
<script>
//Refreshing the page every 5 minutes
setInterval("location.reload()", 300000);
</script>

Related

avoid autopost back asp.net

i am working on a web application using asp.net c#. it has multiple textbox controls like
TextboxA TextboxB TextBoxResult1
TextBoxX TextBoxY TextBoxResult2
i am doing some calculation on TextboxA,B,X,Y and displaying result to TextBoxResult1 and TextBoxResult2 using Ontextbox_change event.
my question is that On each calculation my page is going to refresh.i need to know how can i do this without auto post back . i don't want to use code other than c# like Ajax, java script, jQuery etc.
AutoPostback=true;
thanks in advance
You can't. The code on a view is done at render and is then static html. In order to update the information you either do what you're doing (POST back) or use ajax to post back to the controller but only update specific information instead of refreshing the entire page. You could look into Blazor, but it's still experimental and not fully released (I can't comment on it, haven't used it myself yet).

how to create a decorator proxy page in asp.net 3.5

I am trying to make this feature, and I'm really stuck.
I have two applications that run on the same domain. and I need to have one application load pages from the other one inside it's own (the first) master page.
I have full control of the code of both sides, of course.
I have tries using HTTPRequest, and HTTPResponse, and I have tried using WebBrowser. Both work great as long as I have static(plain HTML) pages. However,
those pages are actually dynamic. the user need to press server-side buttons (postback) and generally use the session, viewstate, and/or cookies.
because of that, HTTPRequest and WebBrowser fail me, as they do not cause postback, and therefore those server-side controls are not working. more so, if I try to "fake" a postback by saving the ViewState after each response and than resend it on the next request, after a few (3-4) times the original page will return a "The state information is invalid for this page and might be corrupted" error, even if I use
EnableViewStateMac ="false" EnableSessionState="True" EnableEventValidation ="false" ValidateRequest ="false" ViewStateEncryptionMode ="Never
So... any ideas how can I solve this issue?
Thanks in advance
What is the main desire here?
Wrap one site's content in another without any architecture changes?
ANSWER: Iframe
Have a single submit button submit from two sites?
ANSWER: Not a good idea. You might be able to kludge this by creating a scraper and parser, but it would only be cool as an "I can do it trophy". Better to rearchitect the solution. But assuming you really want to do this, you will have to parse the result from the embedded site and redirect the submit to the new site. That site will then take the values and submit the form to the first site and wait for the result, which it will scrape to give a response to the user. It is actually quite a bit more complex, as you have to parse the HTML DOM (easier if all of the HTML is XHTML compliant, of course) to figure out what to intercept.
Caveat: Any changes to the embedded site can blow up your code, so the persons who maintain the first site must be aware of this artificially created dependency so they don't change anything that might cause problems. Ouch, that sounds brittle! ;-)
Other?
If using an iFrame does not work, then I would look at the business problem and draw up an ideal architecture to solve it, which might mean making the functionality of the embedded site available via a web service for the second site.

JQuery UI Modal Form Dialog Save Data To Database

I am using the JQuery UI Modal Form Dialog and trying to save the old data and new data to a database. I am using C# (backend) and ASP.NET front end. I can delete new entries, I just don't know how to save the data. I have tried searching ways to pull pull the HTML data in, but couldn't get rid of the errors. Also Wasn't sure if there was a better method? Here is my JSFiddle
function addUser() {
I need to figure out a way to get the data from the table and post it to the server.
I think what you may be looking for is web methods, it allows the jquery (client side) to call the backend (c#) and for them to interact with each other.
Check out this link for reference:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Here is a brief summary from the website:
When it comes to lightweight client-side communication, I’ve noticed
that many of you prefer ASP.NET AJAX’s page methods to full ASMX web
services. In fact, page methods came up in the very first comment on
my article about using jQuery to consume ASMX web services. Given
their popularity, I’d like to give them their due attention. As a
result of Justin‘s question in those comments, I discovered that you
can call page methods via jQuery. In fact, it turns out that you can
even do it without involving the ScriptManager at all. In this post, I
will clarify exactly what is and isn’t necessary in order to use page
methods. Then, I’ll show you how to use jQuery to call a page method
without using the ScriptManager.
I found this:
This script gets data from the table that you can then parse through.
You could then pass it into a hidden field.

Search engine optimization for database loaded using jQuery

I am currently optimizing my site for search engines. It is mainly a database driven site. I am using C# on the back end but database content is loaded via jQuery ajax and a web service. Therefore, my database content is not in html at the point that the bots will crawl it. My site is kind of like an online supermarket format in that there are thousands of items in my database, users can load a single one of these or more onto the web page at a time and the page does not change significantly once items are loaded.
My question is, how (if at all) can I get my database contents indexed? I was thinking of having an anchor that links to an aspx page (eg called mydatabase) which loads all of my database items as a big html list. Then, using jQuery, I would make the anchor invisible to users. The data would still be accessible to users but not by this link, it would be accessed by using the jQuery interface I have created.
The thing is, I don't really want users to see this big, messy list - would google results show this page eg www.mysite.com/mydatabase.aspx as a search result? Also would google see this as "keyword rich" spam page? I have done quite a lot of research but found nothing on this. only instructions for php. Please help I'm not sure what to do and need to know the best way to go about this.
It's a shame you haven't taken the progressive enhancement approach as it would mean you would have started with a standard HTML output that's crawlable, and then adding the layering behaviour (AJAX) on top for the user experience.
Providing a single file (e.g. mydatabase.aspx) that lists all of your products in a list format provides no real value for the reason you gave - it would just be a big useless list. No editorial content relevance for each link etc.
You're much better off taking another look at your information architecture and trying ensure that each product is accessibile by it's own unique URL, then classifying the products into groups (result pages), being careful to think about pagination.
You can still make this act like a single-page application using AJAX, but you'd want to look into HTML5's History API to achieve this in a search engine friendly way.

What technology allows page content to change without changing the URL?

I have seen this on some survey websites. What is the C# code they use on the client side to keep the URL same, but when clicking the "Next" button, the same aspx page is maintained
without having any query string;
without any change even a character in the url; and
the grid, the data , the content, the questions keep changing?
Can anyone give a code-wise example how to achieve this?
My main query is how is this done in code-behind to change data of page and maintain same url.
Nothing simpler that a session, maintainted at the server side. Store a "current question number" in session, increment it at each succesfull postback and you have what you ask about.
Another possibility - a cookie which contains "current question number".
Both cookie and session are invisible in the query string of course.
"change data of page and maintain same url." Answer is Server.Transfer.
This method will preserve url.
The Next button may submit a form using the HTTP POST method. The form data may contain the session, question and response data. The site uses that to build a new response. Unlike a GET, a POST does not incorporate data into the URL.
Developers will typically accomplish this task by using AJAX. The basic premise behind it is that only a certain portion of the page (e.g. a grid or content area) will make a server call and retrieve the results (using Javascript). The effect achieved is that there has not been a full post back, which is why you don't see the URL or parameters changing.
It is possible to do this using jQuery, pure Javascript, or Microsoft's UpdatePanel.
oleksii's comment has some good links as well:
That's the AJAX magic. There are many JQuery plugings for this, for
example this one with a live demo. You can also program it easily
using JQuery Get or Post or any other wrapper that use XmlHttpRequest
object.

Categories