ASTreeView – Perform PostBack while deleting nodes

By | May 22, 2010

How to do a postback after a node being deleted?

Here’s the steps:

1. Set the OnNodeDeletedScript property of ASTreeView.

OnNodeDeletedScript="deletedHandler(val)"

2. Add a hidden button and a textbox(both are server side control) to the page:

<div style="display:none;">
	<asp:Button ID="btnPostBackTrigger" runat="server" OnClick="btnPostBackTrigger_Click" />
	<asp:TextBox ID="txtIDContainer" runat="server"></asp:TextBox>
</div>

3. Implement the deletedHandler javascript method:

<script type="text/javascript">
		
	//parameter must be "val"
	function deletedHandler( val ){
		
		document.getElementById( "<%=txtIDContainer.ClientID %>" ).value = val;
		document.getElementById( "<%=btnPostBackTrigger.ClientID %>" ).click();
	}
	
</script>

4. Implement the Server Side method of postback:

protected void btnPostBackTrigger_Click( object sender, EventArgs e )
{
	string deletedNodeId = this.txtIDContainer.Text;

	//do anything you want on server side.
	//for example, update another tree using the deletedNodeId
}

That’s it.