Saturday, August 25, 2007

Ajax Service Method

1. Create web service with [System.Web.Script.Services.ScriptService()] attribute in class level

2. add Service Reference... in service manager
asp:ServiceReference Path="MyAjaxService.asmx"


3. Add javascript method

function Bt1_OnClick()
{
MyAjaxService.SayHello("Kurniawan",OnComplete,OnError);
}

function OnComplete(result)
{
alert("OnComplete : " + result);
}


function OnError(result)
{
alert("OnError : " + result._message);
}

Thursday, August 23, 2007

using AjaxPro2.dll from Michael Schwarz

*Add web Config configuration/configSections

section name="ajaxSettings" type="AjaxPro.AjaxSettingsSectionHandler, AjaxPro.2"



*Add web Config configuration/system.web/httpHandlers
add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"



*add reference AjaxPro2.dll into the bin folder
using AjaxPro;

* in page load (postback and not) - add
Utility.RegisterTypeForAjax(typeof(_Default));

*
On client ajax method add attribute
[AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public string MyAjaxMethod(string username)
{
return "Halo" + UserName;
}


*call in client javascript
_Default.MyAjaxMethod("Kurniawan").value