CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 12/14/2006 3:53:55 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 15 Views: 64 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
16 Items, 1 Pages 1 |< << Go >> >|
oshoval
Asp.Net User
TreeView - How can Node be Selected twice sequentialy?12/14/2006 3:53:55 PM

0/0

I have a TreeView As a control that the users select Node and the selectedNode text is written in a Textbox...

The problem i have if the user select time after time the same Node the Event - TreeView1_SelectedNodeChanged won't fire in the second time!!!

So how can this SelectedNodeChanged be fire eventhough the user selected the same Node?!

jose_jimenez
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?12/14/2006 8:00:47 PM

0/0

Well, the node has not changed, so you can't have the selectednodechanged event fire, but you can have an onclick event.  You might have to add it to each node as you bind your datasource or as you create it. 

 --JJ


Please mark as answered if I helped.
I don't answer personal emails unless I know you or of you. Feel free to post in the forum to get an answer from me.
maxald
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/9/2007 12:52:11 AM

0/0

I have the same issue... how do I add an onclick event on every node?
akjoshi
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/9/2007 6:57:37 AM

0/0

Hi max,

You can attach a onclick event to full treeview and in javascript you can achieve what you want to do.

I dont know any way by which we can assign an eventhandler to each node, so i will suggest you to use javascript.

Add this in your page

<script type="text/javascript">

function client_OnTreeNodeChecked(event)

{ var TreeNode = event.srcElement || event.target ; // The clicked node


 document.getElementById('<%=YourTextBoxId.ClientID%>').value =TreeNode.nextSibling.title;

}

</script>


Add this in you code behind to attach this function with treeview click, in Page_Load,

TreeView1.Attributes.Add("OnClick", "client_OnTreeNodeChecked(event)");

Hope this works for you


Aj
jose_jimenez
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/9/2007 1:52:42 PM

0/0

It turns out there is no onclick event, but there is a navigateurl you can take advantage of:

 protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
    {
        e.Node.NavigateUrl = "javascript:alert('" + e.Node.Text + "');";
    }

 Keep in mind, if you already have a navigateurl, you will have to modify the navigateurl in order to do both actions.  Here, all I am doing is alerting witht the text of the node, you can do any number of things including posting back to the server. 

--JJ


Please mark as answered if I helped.
I don't answer personal emails unless I know you or of you. Feel free to post in the forum to get an answer from me.
maxald
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/9/2007 7:12:17 PM

0/0

Huge thanks, maybe this will do the trick... but I still cant get it right (sorry but Im a novice). Is it possible to execute server side functions width javascript directly? Should I create a hidden button and execute that button from javascript code (but how do I pass parameters this way)? Or should I use querystrings? 

 

pushp_aspnet
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/10/2007 7:16:37 AM

0/0

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
maxald
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/10/2007 6:37:51 PM

0/0

Can't thank you enough! Big Smile Great solution! I did come up width my own solution, but it was not as smooth as this one...
maxald
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/10/2007 6:38:08 PM

0/0

Can't thank you enough! Big Smile Great solution! I did come up width my own solution, but it was not as smooth as this one...
maxald
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/10/2007 7:27:51 PM

0/0

Gah, I still have a problem. Tongue Tied If there is other buttons and stuff on the same page, the TreeNodeClickHandler allways executes. How do I know if it is a second click in my treeview or if it is a click from somewhere else? What I am trying to achive is a menu width some filter functions, for example one dropdownlist that contains sortorder and it is triggered with a click in my treeview. So if I change the sortorder and click the same treenode again nothing will happen as default. Maybe the treeview wasnt supposed to be used liked this, but it really works great if it wasn't for this second click problem...

Anyway, I do have a solution of my own but I guess it contains some awful code... here is my solution, what do you ppl think about it?

First I put one invisible button and a textbox on the page.

<asp:Button ID="SearchB" Style="display: none" runat="server" OnClick="Search_Click" />

<asp:TextBox ID="SearchTB" Style="display: none" runat="server"></asp:TextBox>

 Then I add a javascript in the navigateurl on every node:

protected void MyTree_TreeNodeDataBound(object sender, TreeNodeEventArgs e) {

e.Node.NavigateUrl =

"javascript:menu_search('" + e.Node.Value + "')";

}

Now... when you click a tree view node you run this javascript function where I get some values from two dropdownlists and a textbox (you will have to check the output html to get their id's, they probably wont have the same id that you give them, at least my controls didn't)  and put those values in a comma separated string in my hidden textbox  (SearchTB). Last I execute a function with help from my hidden button (SearchB) from this javascript.

<script language="javascript">

function menu_search(nodeid) {

var searchstr = document.getElementById("ctl00_ContentPlaceHolder_FreeSearchTB").value.replace(/^\s+|\s+$/g,"");

var areaid = document.getElementById("ctl00_ContentPlaceHolder_CountyDLL").value;

var sortid = document.getElementById("ctl00$ContentPlaceHolder$SortOrderDDL").value;

document.getElementById(

"ctl00_ContentPlaceHolder_SearchTB").value = nodeid + "," + searchstr + "," + areaid + "," + sortid;

document.getElementById(

"ctl00$ContentPlaceHolder$SearchB").click();

}

</script>

 

In this funkction I can get all values I need, what node was clicked and all values from my textbox and dropdownlists...

protected void Search_Click(object sender, EventArgs e) {

string[] SearchArr = CatSearchTB.Text.Trim().Split(new char[] {','});

...................

}

pushp_aspnet
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/11/2007 5:30:41 AM

0/0

maxald:

Gah, I still have a problem. Tongue Tied If there is other buttons and stuff on the same page, the TreeNodeClickHandler allways executes. How do I know if it is a second click in my treeview or if it is a click from somewhere else?

Guys, sorry for that silly mistake, i didn't test the code properly. Thanks to maxlad for pointing it out. I'm posting the revised solution here,

do let me know how it works:

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)
{
TextBox1.Text = "";

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();
string postBackControlId = Request["__EVENTTARGET"].ToString(); //this tells you if treenode has caused a postback

if ((hdnTreeSelectedNodeValue.Value != "") && (hdnTreeSelectedNodeValue.Value == TvSelNodeVal) && (postBackControlId == TreeView1.UniqueID))
{
//same treenode click, selectednodechanged event will not fire
//so execute our treenode click handler
TreeNodeClickHandler(); } else { //different node click, selectednodechanged event will fire
//so only set the hidden variable value
hdnTreeSelectedNodeValue.Value = TvSelNodeVal; } } } protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNodeClickHandler();
}

//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; }
-----------------------------------------
Hope this works fine. 
 

 

 


Home Is Where the Wind Blows
http://pushpontech.blogspot.com
maxald
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/11/2007 11:22:33 AM

0/0

This one solves it all, you are the star of today! Huge thanks! Big Smile
jose_jimenez
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?1/11/2007 1:43:49 PM

0/0

A few things of note.

  1. When you create javascript that references a server control (aspx control with runat=server) always create the script in codebehind during page load or another page initialization event.  Use controlname.ClientId to get the name of the control as seen on the final page (the name that you can use in javascript).  Then register the script using registerclientscriptblock so it can be used.
  2. If you want to postback from javascript use a page postbackreference created in code behind in your javascript.
  3. Research __EventTarget and __EventArgument to find out which control caused the postback on your page.

Please mark as answered if I helped.
I don't answer personal emails unless I know you or of you. Feel free to post in the forum to get an answer from me.
meddev
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?2/3/2007 8:30:40 PM

0/0

I'm not sure if my situtation is exactly the same, but I think it is, and my solution is a bit simpler.  First of all, my scenario is that I provide users with a list of categories, they click one and I switch the view on the page and provide them with the items in the selected category.  The results view has a "Return to Categories" linkbutton on it that simply changes the view back to the category tree.  The problem I was having is that the user could click any other category and get the appropriate results, but they could not click the original category again.  So I fixed the problem by resetting the selected node in the SelectedNodeChanged event handler:

protected void CategoryTree_SelectedNodeChanged(Object sender, EventArgs e){

TreeNode node = CategoryTree.SelectedNode;

//allows for backing up then clicking the node again.

node.Selected =

false;

...//retrieve results code//... 

}

 

Monika Aleksiev
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?4/5/2007 7:17:37 AM

0/0

Thanks for this solution. It is enough to check  Request["__EVENTTARGET"]. That is exactly what I need to resolve this problem :)
g08h
Asp.Net User
Re: TreeView - How can Node be Selected twice sequentialy?3/17/2008 10:31:00 PM

0/0

Thanks pushp_aspnet ,  thats was a perfect solution to capturing the onclick of the TreeView when it has not changed.  Good work!!!

16 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
TreeView - How can Node be Selected twice sequentialy? - ASP.NET ... TreeView - How can Node be Selected twice sequentialy? Rate It (2). Last post 07 -09-2008 10:22 AM by shaikphakeer. 17 replies. Sort Posts: ...
Release Bulletin PowerBuilder Desktop/Professional 9.0 Release ... May 14, 2003 ... In PowerBuilder 6, using the right mouse button to select a TreeView item caused it to become permanently selected. ...
Contents combination of nodes or clades on a tree. Printing with these selected with print their highlighting too. Once selected, one can opt to create text files ...
User Interface tutorial The text output area can be selected to be either spreadsheet-like with ... node in the system tree view refers to one of these folders and consists of an ...
A modular network model of aging Once the P–D aging pattern starts, the flies can live about another adult ..... Then the nodes in each ordered list are sequentially attacked according to ...
AdaptiviTree: Adaptive Tree Visualization for Tournament-Style ... The DOI function can pay attention to such nodes as. the selected nodes, their ... Most classic bracket visualizations offer a horizontal tree-view to ...
between 0 and # columns that service node under the module which contains the service, right-click. the service and select. Import service . You can edit services defined in a ...
(WO/2004/019230) METHOD, SYSTEM, AND APPARATUS FOR GENERATING ... In a tree view representation of the schema, each element of the schema is represented as a node. Each node can have one or more child nodes. ...
Release Notes for P4V, the Perforce Visual Client Release 2007.2 ... (Bug #9656) ADDRESS BAR The new address bar lists the path of the currently selected file or folder in the Depot/Workspace tree view. The address bar can ...
The formalization of medical protocols: easier said than done. user can insert. These elements are organized in a tree, which is represented by the list. boxes: each box shows the contents of the node selected in the ...




Search This Site:










how to pass variable between .ascx and its parent .aspx (global variable not working?)

execute method

replication

simple question about reading from a db...

how to use already deveoped html template in .aspx page

getting active tcp/udp connections using .net libraries

can i limit the number of words in a text box?

what is wrong with this?

internet explorer can't open te internet site .... error

asp.net and sql 2000

dll file

how to get upperbound in array

html page inconsistent with microsoft asp.net 2.0 step by step

number formatting disappears when writing to csv

format sql server true/false to yes/no

parameter in html codes!

how to have a splitpane on a asp.net web page?

problem to add a local component reference!!!

doctype html public - problem

printing in asp.net

should add reference to a class library project dll be to the bin folder or the obj\debug folder

help regarding video chat

images not showing during run time

adding an sql database to my server

machine.config and web farms

how to create a my space web site

partial keyword

storing a datatable in a database.

request field validator problem

retrieving a cookie and getting error

  Privacy | Contact Us
All Times Are GMT