| ASPTreeView Server-Side Events
|
| | |
The server-side events are being triggered using
the client-side events and our free AJAXPage control.
First you have to download the AJAXPage component.
Please visit the AJAXPage section for more information
about how to download and use the AJAXPage control.
You can also use our obout_Tree_DB component.
It allows you to update any changes in treeview
like adding/deleting nodes, editing, drag-and-drop, etc.
on server-side database automatically without writing code.
| | |
Enabling the events
To enable the server-side events,list the names of the events separated with commas
in the EventList property (no spaces).
Example:
oTree.EventList = "OnNodeSelect,OnNodeDrop,OnAddNode";
Full list:
oTree.EventList = "OnNodeSelect,OnNodeEdit,OnNodeDrop,OnAddNode,OnRemoveNode,
OnNodeExpand,OnNodeCollapse,OnBeforeNodeEdit,OnBeforeAddNode,
OnBeforeRemoveNode,OnBeforeDrop,OnMoveNodeUp,OnMoveNodeDown";
| | |
Sending the data to the server-side events
All the events use the AJAXPage control to post data to the server
(without reloading the page) and return the result to the client.
A set of parameters is being sent for each event. To change the name
or these parameters or to use the result returned from the server
you have to open the ob_events_xxxx.js file and edit the
events you need.
For example, the ob_OnNodeEdit function, which is executed every time
a node is edited:
function ob_OnNodeEdit(id, text, prevText)
{
// add client side code here
//alert("OnNodeEdit on " + id + "\n text: " + text + "\n prevText: " + prevText);
if(ob_ev("OnNodeEdit"))
{
if(typeof ob_post != "undefined")
{
ob_post.AddParam("id", id);
ob_post.AddParam("text", text);
ob_post.AddParam("prevText", prevText);
//Change "TreeEvents.aspx" with the name of your server-side processing file
var sResult = ob_post.post("TreeEvents.aspx", "OnNodeEdit");
//use the result returned from the server:
alert(sResult);
}
else
{
alert("You have to add the AJAXPage control to your page in order to use the server-side events!");
}
}
}
There are 3 parameters that will be sent to the server:
id, text and prevText
You can use the result returned from the server into your client-side functions.
| | |
Implementing the server-side methods
Each event needs to have a corresponding server-side method, that will be executed
when the event is triggered. These methods are declared in the server-side processing file
(TreeEvents.aspx in our example) and must have the same name as the event
and their arguments must be the same as the ones specified on the client-side.
For example, the OnNodeEdit method:
public string OnNodeEdit(string id, string text, string prevText)
{
return "This is the server response: for OnNodeEdit";
}
The value returned by the server-side methods will be available on the client-side
(this is what the ob_post.post function returns)
| | |
| "Great work on the suite - I'm lovin' it." |
Dave Vanderkloot |
|
| | |
|