Search Web

Thursday, August 19, 2010

About AJAX !!

What is Ajax ??

Ajax is a way of developing Web applications that combines:

    * XHTML and CSS standards based presentation
    * Interaction with the page through the DOM
    * Data interchange with XML and XSLT
    * Asynchronous data retrieval with XMLHttpRequest
    * JavaScript to tie it all together

In the traditional Web application, the interaction between the customer and the server goes like this:

   1. Customer accesses Web application
   2. Server processes request and sends data to the browser while the customer waits
   3. Customer clicks on a link or interacts with the application
   4. Server processes request and sends data back to the browser while the customer waits
   5. etc....

There is a lot of customer waiting. 

Ajax Acts as an Intermediary

The Ajax engine works within the Web browser (through JavaScript and the DOM) to render the Web application and handle any requests that the customer might have of the Web server. The beauty of it is that because the Ajax engine is handling the requests, it can hold most information in the engine itself, while allowing the interaction with the application and the customer to happen asynchronously and independently of any interaction with the server.

Asynchronous

This is the key. In standard Web applications, the interaction between the customer and the server is synchronous. This means that one has to happen after the other. If a customer clicks a link, the request is sent to the server, which then sends the results back.

With Ajax, the JavaScript that is loaded when the page loads handles most of the basic tasks such as data validation and manipulation, as well as display rendering the Ajax engine handles without a trip to the server. At the same time that it is making display changes for the customer, it is sending data back and forth to the server. But the data transfer is not dependent upon actions of the customer.
Ajax is Not New Technology

Ajax is instead a new way of looking at technology that is already mature and stable. If you're designing Web applications right now, why aren't you using Ajax? Your customers will thank you, and frankly, it's just fun

That's It ..!!



How to Store Values In View State..??

ASP.NET has a built in mechanism for storing values of controls known as ViewState.
The ViewState property provides a key-value object for storing values between multiple requests of the same page.
ASP.NET saves the state of the page and controls as a hashed string in the page as a hidden variable, ViewState.
When a page is run, the ViewState property can be seen from the source code of the page.


<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" 
value="/wEWAgL3ku32BwLs0bLrBqcPjj4o1kvxlT2D91sy/YSkJDTh" />


Custom data can be stored in the ViewState property.

If a value has to be stored for a user in page, ViewState is an easy way to achieve this.
Please note that ViewState property is only accessible from the page only.
If the user visits a different page, the ViewState property will be lost.

Let's create a string containing a date and store it in the ViewState.


string date = DateTime.Now.ToString();

ViewState["date"] = date;

An alternative way of achieving this would be to


ViewState.Add("date", date);


The values stored in the ViewState can also be retrieved as follows.


if ((string)ViewState["date"] != null)

{

string date2 = (string)ViewState["date"];

}
>

Here, I am checking there a ViewState property named "date". If so, assign the value to string date2.
In ViewState, objects can also be stored/ For example, we can store a DateTime object like below

ViewState.Add("date3", DateTime.Now);

and retrieve the object like

DateTime date3 = (DateTime)ViewState["date3"];


That's It....!!