Beruflich Dokumente
Kultur Dokumente
Step 4 In the codebehind of your page, add functions (like you normally would) that you
'd like to be able to asynchrounsly called by client-side scripting. Mark these
functions with the Ajax.JavascriptMethodAttribute():
//C#
[Ajax.AjaxMethod()]
public int ServerSideAdd(int firstNumber, int secondNumber)
{
return firstNumber + secondNumber;
}
'VB.Net
<Ajax.AjaxMethod()> _
Public Function ServerSideAdd(ByVal firstNumber As Integer, ByVal secondNumber A
s Integer) As Integer
Return firstNumber + secondNumber
End Function
The wrapper will automatically create a JavaScript function named "ServerSideAdd
" which accepts to parameters. When called, this server-side function will be c
alled and the result returned.
Step 5 Using JavaScript, you can invote the ServerSideAdd function like you would any o
ther JavaScript function. You can call it using the two parameters, or optional
ly pass a call back function. The name of the function is, by default, <name of
class>.<name of server side function>, such as Index.ServerSideAdd:
alertIndex.ServerSideAdd(100,99));
OR
Index.ServerSideAdd(100,99, ServerSideAdd_CallBack);
function ServerSideAdd_CallBack(response){
alert(response.value);
}
The response exposes three properties, error, value and request.
Note that you can return more complex objects that simple types.
See the demo for additional information:
http://ajax.schwarz-interactive.de/csharpsample/default.aspx