Articles of level

While you make an AJAX call and get some data from server, it is good to show a progress bar or image to user so that (s)he knows that something is going on. Hence Loading… text is common in AJAX enabled application.

One solution that you can use to handle the session timeout errors is using JSON or XML format as output for your AJAX requests.

While submitting a form using AJAX, one has to create a input string that contains the value of all the input elements on the screen. It is very difficult to create this string if your form is very big. Hence we can use jQuery’s serialize() and serializeArray() method to do so.

HTTP errors like 404, 503 are sometimes tedious to handle using AJAX. There is a simple trick to solve this problem. First let us see simple AJAX handler function that we use to get response XML/text through AJAX.

GET Request method using jQuery
Load a remote page using HTTP GET request method. This is an easy way to send a simple GET request to a server. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code).

Sometimes, we required to show all items in Gridview or repeater but we do not want to implement paging. In this case, a scrolling grid is more applicable and enclosing the GridView in a Panel control or <div> tag with the overflow style applied ensures that the over-sized element is clipped and that scroll bars are displayed.
This solution works fine but whenever a postback occurs on page the div gets back to its original starting position. Here in this example, In order to maintain the scrolled position after postback I stored the div scroll value in hiddenfield using jquery and after postback we can get the scroll value from hiddenfield and set back to div to maintain the scroll position after asynchronous postback.

ASP.NET AJAX enables a process known as an asynchronous postback. This is similar to a standard postback in that the view state of controls on the page is sent to the server in response to an event on the page. In an asynchronous postback, however, the XMLHttpRequest object is used to send the view state to the server. Then, the response that is returned by the server is used to update the controls on the page without having to reload the entire web page in the browser. Figure shows the three components of ASP.NET AJAX and illustrates how they work. The ASP.NET AJAX client-side framework is a JavaScript library that is loaded by the web browser when an AJAX-enabled ASP.NET page is displayed. It allows JavaScript code to interact with the ASP.NET application server through the XMLHttpRequest object it encapsulates.

To create this important Ajax object, you are going to have to use a special programming technique known as "try and catch". Basically it attempts to "try" a piece of code and if that piece causes an error it "catches" the error and keeps going. Normally when an error occurs the code will stop running, however, the "catch" eats up the error and lets the code continue.

onreadystatechange property

This function will be used to catch the data that is returned by the server.The XMLHttpRequest object has a special property called onreadystatechange. onreadystatechange stores the function that will process the response from the server. The following code defines an empty function and sets the onreadystatechange property at the same time!
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
// We still need to write some code here
}

This property, onreadystatechange, stores a function. As the name sort of implies, every time the "ready state" changes this function will be executed. 

You can use Visual Studio to work faster and more efficiently when you write, navigate, and debug your code. There are some tricks which is helpful to every programmer-

PreviousDisplaying 2 of 2
1 2
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*