Search This Blog

AJAX & .Net

AJAX & .Net

AJAX is abbreviation of "Asynchronous JavaScript and XML". AJAX is based on JavaScript and HTTP requests. Using Ajax in .Net is really simple and easy. Very basic steps:

Suppose our class name of webform is : MyWebForm1
(1) Add Ajax.dll in website project referrence.
(2) Register class on PageLoad for Ajax.
(3) Mark methods that can be called through AJAX.
(4) Call server side methods : Synchronously/ASynchronously
(5) Manipulate returned value

Here we go:
(1) Add Ajax.dll in website project:
            As we add any other reference in website, add this reference also :)

(2) Register class for Ajax use on page load:
In page load event handler : (C#)
protected void Page_Load(object sender, EventArgs e)
add: Ajax.Utility.RegisterTypeForAjax(typeof(MyWebForm1));      

(3) Mark method that can be called through AJAX: (C#)
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public int GetSquareAjax(int val) { return val * val; }

(4a) In JavaScript : To call a server side method ASynchronously, call method
as
val returnValue = MyWebForm1.GetSquareAjax(44).value;
where
  • MyWebForm1 = Type
    registered for AJAX in Page Load of webform
  • GetSquareAjax
    = MethodName
  • 44 = Parameter
    Value
  • returnValue = will have returned value.

(4b) In JavaScript : To call a server side method ASynchronously, call method
as
MyWebForm1.GetSquareAjax(44, ServerCallBack_GetSquareAjax);         
where
MyWebForm1 = Type registered for AJAX in Page Load of webform
  • GetSquareAjax
    = MethodName
  • 44 = Parameter
    Value
  • ServerCallBack_GetSquareAjax
    = Call back function (should be written in javaScript)
 

this Call back function can be like:
function ServerCallBack_GetSquareAjax(ajaxReturnValue){
}

Note in above function there is one parameter; named= ajaxReturnValue. This is object and
have following properties:
  • request
  • error
  • value
  • context

Most important amoung these
properties are
  • value
  • error

'value' will have return value (Note if object is returned from server then 'value' property will have all exposed
properties of returned object.

'error' will have error value (if there is any error on server side)
           
 

PS : Please note that due to
hosting issues of code4coder group, right now we cannot upload examples/code
right now. We are working on it.



Reflection,System.Reflection,Creating objects dynamically trhough reflection, code4coder.com,code4coder, c#,asp.net,vb.net,pl/sql,advanced features, code, coder, coders, reflection,system.reflection,System,using System.Reflection,Assembly,ConstructorInfo,Object,MethodInfo,Convert.ToString(),asp,slq,optimized code,email,sqlldr,Invoke,Type,Type[],Ajax,Cell Phone, Mobile Phone, Coding, Code,using System, using System.Collections, using System.Net, Constructor, Destructor, Object oriented programming, ebook, learning, UMT, code, freak, programmer, programmer's heaven, sql, optimization query, best SQL query writing, Query SQL, Best practices, Problems, Issues, C#, .Net, . Net, C# .Net, C#.Net, VC, VC#,Threads,Multithreading,Trim(),javascript, jScript, JavaScript, jQuery, client site, server side, client, server, group by, order by, max() over, count() over, dense_rank(), rank(), dense_rank, rank, Email, SQLLDR,C# help, help, coding help, HP, Application, Software Engineer

3 comments: