Hi
In this post I will show you how to use the incremental Page fetch using the Asp.Net Ajax. This is very important if you want the user to e shown some part of the page and then to populate the other part of the page subsequently. With the help of the Asp.Net Ajax this is very easy.
First we need to create a web service that will return the Html that will be displayed. For this Example I have taken a web service that returns a string that will be displayed in the div. Here we must remember to put the System.Web.Script.Services.ScriptService() with the class since the webservice will be accesed by the javascript proxy.
Now we need to write some javascript code in the page were the data will be fetched after the page load and displayed.
We will code for the page load function of the page. In the page load event we will call our web service and fetch the string. And then we will display this string in a DIV.
But don’t forget to add the script manager with the reference to the service class in it. Now in the page load event we will write some simple JavaScript code to call the web service
<script type="text/javascript" language=javascript>
function pageLoad(){
ret = WebService.HelloWorld(OnCom,OnTimeOut,OnErr);
}
function OnCom(result){
document.getElementById("div1").innerHTML=result;
}
function OnTimeOut(result){}
function OnErr(result){}
</script>
Here we are calling the Hello world function in the given web service (The web service name is defined in the Service tag of the script manager). We are passing the function name as the parameter. We are passing the function name for oncomplete event, OnTimeOut event and on error event.
Here I am doing nothing the on timeout or on error. In the on complete event I am changing the innerHTML of the Div with the string passed back from the server.
That’s all we need to do to implement the incremental page fetch mechanism. Remember you can call many web service and they will be called asynchronously. And hence will give user the effect of incremental page display.
Thanks
Vikram