When you need to:
- Call web server and perform some operation on server like updating database or some File I/O operations or have to queue the requests and have less to do on client side like just need to show Operation completed or data based updated.
- Send request to web server asynchronously and don’t want to put user on wait for completion of request
- Perform operation on server side more efficiently as you wont follow page life cycle
When you don’t need to:
- Initiate Page object and/or need to follow page life cycle
- Post back page and Render page automatically
- Send request to web server synchronously and put user on wait of completion of processing
- Submit form
- Use cache, session or need to access any asp.net intrinsic object
For more details and better understanding please visit following link http://worldofasp.net/tut/ajax_webservice/Ajax_enabled_web_service_237.aspx
Normally, when you have to do some operation at server side, say some database oriented operation like any of well known CRUD (create, retrieve, update and delete) operations. You will submit whole form/page to server and get a whole new page from server to re paint on your browser. In very few, situations that are ok but mostly its not required at all.
You fill those textboxes and want to save given information in database and then clear the textboxes. Sounds good!
But what happen, when you click on submit button, all the contents on the web page will go to the server like header, footer, navigation bar and your textboxes. Purpose of submit button was to save information given in database then why header, navigation bar and footer being sending to server. I guess, it doesn’t make sense until they are needed to update.
So, if you want to send your specific controls data only to server and want to update those controls at browser side, then here comes “XMLHTTPRequest” object.
For more details and better understanding please visit following link http://worldofasp.net/tut/XMLHTTPRequest/XMLHTTPRequest_236.aspx