Wednesday 27 February 2013

ASP.NET: Ajax Call To Server Side Function

kailash chandel
To call the server side function we will use the ajax call. For this we need to call the server side function by a ajax call. To explain this we will have an example.
       Let us have a page named ajaxcall.aspx .  We will take a div with id myDiv and put its text  "Before ajax call when server side function is not called." Now place a button with id Button1 .


ASP.NET: Ajax Call To Server Side Function





There is a method named ServerSideMethod defined on ajaxcall.aspx.cs page.  This method returns the text  "After ajax call when server side function is  called".


ASP.NET: Ajax Call To Server Side Function







Now we want to call the  method ServerSideMethod   on the click of button Button1   and change the text of div myDiv to the message returned by ServerSideMethod. To do this we will make the ajax call to the method by following code:
Firstly add the reference:-
ASP.NET: Ajax Call To Server Side Function
After that write the code:
ASP.NET: Ajax Call To Server Side Function
  

Now when we run the program we have the initial screen:

ASP.NET: Ajax Call To Server Side Function

And after click on the Check button output will be:-

ASP.NET: Ajax Call To Server Side Function


The text of the paragraph has been replaced by the message returned by the method  ServerSideMethod.







No comments:

Post a Comment

How to get code from a published ASP.Net build where we don't have source code?

If you have ever lost or misplaced your source code for an ASP.Net web application, you might wonder if there is a way to recover it from th...