Hi,
This is quite a recurrent requirement posted on these forums and no workable solution has yet been posted( at least in my knowledge) so i thought of giving it a try. Think i have arrived at a solution:
1) put a hidden field in the .aspx page as:
----------------------------
<asp:HiddenField ID="hdnTreeSelectedNodeValue" runat="server" />
---------------------------
2) code behind should look like:
---------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
//getting the value of the hidden variable that holds the value
//of selected node, this variable is a part of treeview design
string TvSelNodeHdnFldId = TreeView1.ClientID + "_SelectedNode";
string TvSelNodeVal = Request[TvSelNodeHdnFldId].ToString();
if (hdnTreeSelectedNodeValue.Value != "" && (hdnTreeSelectedNodeValue.Value == TvSelNodeVal))
{
//same treenode click, selectednodechanged event will not fire
//so execute our treenode click handler
TreeNodeClickHandler();
}
else
{
//different node click, selectednodechanged event will not fire
//so only set the hidden variable value
hdnTreeSelectedNodeValue.Value = TvSelNodeVal;
}
}
}
//handler for SelectedNodeChanged event
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNodeClickHandler(); //just call the helper function here
}
//helper function having code to be executed on the click of a treenode
private void TreeNodeClickHandler()
{
TreeNode selectedNode = TreeView1.SelectedNode;
//play with selected node
TextBox1.Text = selectedNode.Text;
}
------------------------------------
The idea is to have a helper function that would be made to execute on the click of a treenode(whether re-click or not). A couple of hidden fields are put on the page when a tree view is rendered, one of those keep the track of the selected node. I used it(by retrieving its value from the request collection) to check if the an already selected node is clicked or not.
Hope this helps.
Home Is Where the Wind Blows
http://pushpontech.blogspot.com