1. Add an application (Ajax. dll ).
2. Configure web. config.
< System . Web >
< Httphandlers >
< Add Verb = "Post, get" Path = "Ajax/*. ashx" Type = "Ajax. pagehandlerfactory, Ajax" />
</ Httphandlers >
</ System. Web >
3. C #UsingSystem;
PublicPartialClass_ Default: system. Web. UI. Page
{
Protected VoidPage_load (ObjectSender, eventargs E)
{
Ajax. Utility. registertypeforajax (Typeof(_ Default ));
}
[Ajax. ajaxmethod ()]
Public StringServersideadd (IntFirstnumber,IntSecondnumber)
{
ReturnFirstnumber+Secondnumber;
}
}
4. aspx <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default " %>
<!Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Ajax to call the server-side Method Test </ Title >
< Script Language = "JavaScript" Type = "Text/JavaScript" >
<! --
FunctionServermethods ()
{
_ Default. serversideadd (100,99, Serversideadd_callback );
}
FunctionServersideadd_callback (response ){
Alert (response. value );
}
FunctionButton1_onclick (){
Servermethods ();
}
//-->
</Script>
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Input ID = "Button1" Type = "Button" Value = "Button" Language = "JavaScript" Onclick = "Return button1_onclick ()" />
</ Form >
</ Body >
</ Html >