Introduction
The basic idea of designing this module is to give an idea to call server side methods or sever side script using java script and Asp.Net. In this example I am calling Static methods and non static methods using two different techniques. Most of programmer are aware of these techniques, here by demonstrating it, I am trying to simplify things.
1) Using Ajax.Net Script manager to call static methods
2) Client call back to call non static methods
Using Ajax.Net Script manager to call static methods:
Important points to note down while using this technique:- .aspx page
Step 1: Make property EnablePageMethods="true" Of ScriptManger
Step 2: To call server side method in client side script use 'PageMethods' object which is created by Script manger implicitly.
Step 3:To get the result back on client side use the following method
Step 4:To catch any error if happened durin processing use
Use .cs file:-Step 5::Mark your public method in code behind with System.Web.Services.WebMethod and with static modifyier
Using Client call back to call non static methods:
Important point to node down while using this technique:-
User .cs file:-Step 1 : First of all your page class should implement ICallbackEventhandler and its two methods GetCallbackResult() and RaiseCallbackEvent()
Step 2:Register Client side call back method signature from code behind using GetCallbackEventReference method of ClientScriptManger class
Step 3 : Register one more client side function which actualy call the RaisCallbackEvent mehotd in server side script , using RegisterClientScriptBlock method of ClientScriptManger class as CallServer() this method implicitly call Client side callback methods in order to make some kind of data communication with Server.
Step 4:Define server side method and call it inside RaiseCallbackEvent() method.
Step 5: And result will be send back by GetCallBackResult() methods from the code behind
Step 6: Define the method signature using java script which were declared in step 2
Step 7: And make a call to Client side method CallServer() using java script, which were defined in step 3.
Points of Interest
Both of these techniques are very powerful while developer want to pass very small information between client and server.
History
none