How to send back data
The AJAXPage ASP.NET control allows you to send back a response to the client after the
server-side processing is finished. You have multiple options to do this:
1. Return values from the server-side methods. The data returned by these
methods will be the value that the post function returns on the client-side.
public string onEdit(string sNewValue, string sOldValue)
{
// process the information
// .....
return sOldValue + " was replaced with " + sNewValue; // response returned to the client
}
2. If you don't want to receive any kind of response from the server when the
processing is finished, then you have to declare the server-side methods as void.
The post function will return an empty string to the client-side.
public void onClick(string sValue)
{
// server-side processing
// .....
}
3. Another way to send data to the client is to use the server-side ExecBeforeLoad or ExecOnLoad methods.
This methods takes as parameter a javascript command or set of commands that will be executed on the client-side:
- in case of ExecBeforeLoad, before the post function returns the response from the server.
- in case of ExecOnLoad, after the post function returns the response from the server.
public string onSubmit(string name, int age)
{
int ageAdd = 10;
ExecBeforeLoad("alert('something')");
ExecBeforeLoad("customJsFunction(" + ageAdd.ToString() + ")");
return name + " will be " + (age + ageAdd) + " in " + ageAdd + " years";
}
public string onSubmit(string name, int age)
{
int ageAdd = 10;
ExecOnLoad("alert('something')");
ExecOnLoad("customJsFunction(" + ageAdd.ToString() + ")");
return name + " will be " + (age + ageAdd) + " in " + ageAdd + " years";
}
Both ExecBeforeLoad and ExecOnLoad methods can be used more than once for a specific event.
| |