In order to manipulate server-side the data sent with the
post function, you have to follow
these steps when creating the page that will process the data (ProcessPage.aspx in our example).
The process page can be the same as the page where the callback is initiated.
In this case, all the code in the tutorial applies to the same page.
These steps are different, depending on whether you are using the processing page with code behind or not.
1. Your page must be derived from
OboutInc.oboutAJAXPage.
If you are using pages without code behind, add the next line on top of your aspx page:
<%@ Page Language="C#" Inherits="OboutInc.oboutAJAXPage" %>
If you are using pages with code behind, derive your page like this:
public class PageName : OboutInc.oboutAJAXPage
where
PageName is the name of your page.
2. Implement a server side public method for each event you've specified on client side for the post function.
The parameters added with the AddParam function have to be arguments of these methods.
For example, if you used on client side the following code:
ob_post.AddParam("iFirstNumber", 15);
ob_post.AddParam("iLastNumber", 20);
ob_post.post("ProcessPage.aspx", "onCompare");
// if the process page is the same as the page where the callback is initiated, use
// ob_post.post(null, "onCompare");
Then, on server side you have to implement the
onCompare method, using all those parameters as arguments for the method.
If you are using code behind pages, then you need to define the methods like this:
public int onCompare(int iFirstNumber, int iLastNumber)
{
// do something with the numbers
if(iFirstNumber > iLastNumber)
return 1;
else
return -1;
}
If you are using pages without code behind, then you need to implement that method in C#/VB.NET code blocks, like this:
<script language="C#" runat="server">
public int onCompare(int iFirstNumber, int iLastNumber)
{
...
}
</script>
To send a collection to the server you can use an
Array or an
Object.
Client side:
var parameters = new Array();
parameters[0] = "John";
parameters[1] = 24;
ob_post.AddParam('parameters', parameters);
ob_post.post(null, "ComputeAge");
Server side:
public string ComputeAge(ArrayList parameters)
{
...
or
Client side:
var parameters = new Object();
parameters.name = "John";
parameters.age = 24;
ob_post.AddParam('parameters', parameters);
ob_post.post(null, "ComputeAge");
Server side:
public string ComputeAge(Hashtable parameters)
{
...
Please take a look at the example from our archive for details.