Monday, 22 October 2012

How asp.net applications support ajax-based communication?

Yes, using asp.net we can support ajax-based communication with the help of JavaScriptSerializer.

JavaScript objects are prepared by JavaScriptSerializer. Which is called as JSON Support. 
so asp.net implements this serializer for returns data to client in the form of
JSON. 


How asp.net applications supports:       

 Ajax-based applications.

 Using JavaScriptSerializer

Yes, System.Web.Script.Serialization. in this we have
      public JavaScriptSerializer();
      {  //   resolver:
        //     The custom type-resolver object.
        public JavaScriptSerializer(JavaScriptTypeResolver resolver);
      }      
public abstract class JavaScriptTypeResolver
{
     public abstract Type ResolveType(string id)
}
Here Type can be: int,string,customer,Department,Employee,Disti….ect
Type can be any type: int, string,customer….any custom type. So we can serialize any object.
Ex:
   Employee eobj = new Employee { Eid = 41, Ename = "saipavan" };
   Label1.Text=GetJsonMethod(eobj);
    public string GetJSON(object obj)
    {
        System.Web.Script.Serialization.JavaScriptSerializer oserializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        return oserializer.Serialize(obj);
  
    }

Output:


{"Eid":41,"Ename":"saipavan"}---Json format.


No comments:

Post a Comment