Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Treeview Checked Item = False when it is True

Reply
Thread Tools

Treeview Checked Item = False when it is True

 
 
Derek Pettinato
Guest
Posts: n/a
 
      11-05-2003
Hi,

I have a treeview on a webform bound to an external XML
file with checkboxes.

I have some javascript on the page that basically fires
when the checkboxes are checked to uncheck anything that
may be checked in the same node thus allowing only one
node to be checked at one time.

On this form I have a submit button that run some vb
codebehind. All I need this codebehind to do is to go
through the entire treeview and grab all of the items
that are checked. I figured this would be pretty easy
with the .checked property. Not the case as when
debugging the codebehind, the checked value of the node I
checked is always false.

Also, I cannot have the javascript do this as I need to
run back to the server to populate dynamically generated
tables with the data that is checked on the treeview.

My code is below...

'**********button clicked***************
Public Sub TreeSelect(ByVal sender As System.Object,
ByVal e As
Microsoft.Web.UI.WebControls.TreeViewSelectEventAr gs)

Dim dimArray() As String
ReDim dimArray(TreeView1.Nodes.Count)

For i = 0 To TreeView1.Nodes.Count - 1
dimArray(i) = ProcessNodes(TreeView1.Nodes)
Next
'**************************************

'********function*************************
Public Function ProcessNodes(ByVal ParentNode As
TreeNodeCollection) As String

Dim childNode As TreeNode

For Each childNode In ParentNode
If childNode.Checked = True Then
ProcessNodes = childNode.Text
End If
If childNode.Nodes.Count > 0 Then
If childNode.Checked = False Then
ProcessNodes(childNode.Nodes)
Else 'checked!
ProcessNodes = childNode.Text
End If
End If
Next childNode
'*********************************

Thank you in advance,
-Derek.
 
Reply With Quote
 
 
 
 
MSFT
Guest
Posts: n/a
 
      11-06-2003
Hi Derek,

After invest on your code, I think there is a little mistake in it and it
should be:

If childNode.Checked = False Then
ProcessNodes = ProcessNodes(childNode.Nodes)
Else 'checked!
ProcessNodes = childNode.Text
End If

Your original code is :

If childNode.Checked = False Then
ProcessNodes(childNode.Nodes)
Else 'checked!
ProcessNodes = childNode.Text
End If

The result can't be return from under layer call

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


 
Reply With Quote
 
 
 
 
Derek Pettinato
Guest
Posts: n/a
 
      11-06-2003
Hi,

Thank you for your quick response but that did not seem
to fix the problem.

For some reason the value of the checkbox never is true.
I have stepped throough the code watching the values and
when they are checked, they remain False.

I am not sure if the way I have the treeview control
setup has something to do with its code-behind behavior?
The treeview's AutoPostBack property is set to False. I
do not want the treeview to go back to the server until
the user clicks on the Submit button. I use the following
javascript to check/uncheck nodes so there is only one
checked at a time...

'****Page Load Code-Behind********
TreeView1.Attributes.Add("oncheck", "DoCheck(this);")
'*********************************

'****javascript*******************
// Function that allows only one value per Parent Node to
be checked at one time.
function DoCheck(oTree)
{

// Get the node that fired the event...
var oNodeClicked = oTree.getTreeNode
(oTree.clickedNodeIndex);

// Split the clickedNodeIndex to determine the Parent
var strSplit = (oTree.clickedNodeIndex).split(".");

// Set the Parent to 'unchecked' since we are going to
traverse and 'uncheck' all children
var oParentNode = oTree.getTreeNode(strSplit[0]);
oParentNode.setAttribute("checked", false);

// Check if the node is checked or unchecked
var bChecked = (oParentNode.getAttribute("checked")
==true) ? false : true;

// Get the nodes childnodes...
var oColl = oParentNode.getChildren();
//var oColl = oRoot.getChildren();

// Call the function that traverses the nodes
TraverseChildren(oColl, bChecked);

// Set the originally clicked node to checked
oNodeClicked.setAttribute("checked", true);
}

// Recursive function that traverses through the tree and
checks/unchecks the nodes
function TraverseChildren(oColl, bChecked){
var oChild;
for (var i=0;i<oColl.length;i++){
oChild = oColl[i];

// Check/Uncheck the current node by accessing the
setAttribute
(bChecked) ? oChild.setAttribute("checked", false) :
oChild.setAttribute("checked", true);

// If you only want to select 1st level children
// you'll have to comment this line out...
TraverseChildren(oChild.getChildren(), bChecked);
}
}
'*****************************************

....after checking one or many nodes and clicking on the
aspx button 'Select' it seems like the treeview control
gets 'reset' on its way back to the server before the
code-behind runs.

Do you think I may have to resort to hidden fields
populated by the DoCheck javascript function to capture
the values of the checked nodes and then on the Select,
read those hidden fields since the treeview isn't
returning its new values to the server?

Thank you again in advance,
-Derek.

>-----Original Message-----
>Hi Derek,
>
>After invest on your code, I think there is a little

mistake in it and it
>should be:
>
> If childNode.Checked = False Then
> ProcessNodes = ProcessNodes

(childNode.Nodes)
> Else 'checked!
> ProcessNodes = childNode.Text
> End If
>
>Your original code is :
>
> If childNode.Checked = False Then
> ProcessNodes(childNode.Nodes)
> Else 'checked!
> ProcessNodes = childNode.Text
> End If
>
>The result can't be return from under layer call
>
>Hope this help,
>
>Luke
>Microsoft Online Support
>
>Get Secure! www.microsoft.com/security
>(This posting is provided "AS IS", with no warranties,

and confers no
>rights.)
>
>
>.
>

 
Reply With Quote
 
MSFT
Guest
Posts: n/a
 
      11-07-2003
Hi Derek,

Is the problem related to DoCheck method? If you remove the line:

TreeView1.Attributes.Add("oncheck", "DoCheck(this);")

Will you get the correct values in code behind?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Derek Pettinato
Guest
Posts: n/a
 
      11-10-2003
Hi,

Yes, when I remove the line TreeView1.Attributes.Add
("oncheck", "DoCheck(this);") the code behind has the
correct checked values...

So, is there a way to still allow the addition of the
attribute at runtime so the javascript runs when the user
clicks on a checkbox? Or, is there another way for me to
obtain the same results I get on the user click and still
have the code behind have the correct values?

Thank you,
-Derek.
>-----Original Message-----
>Hi Derek,
>
>Is the problem related to DoCheck method? If you remove

the line:
>
>TreeView1.Attributes.Add("oncheck", "DoCheck(this);")
>
>Will you get the correct values in code behind?
>
>Luke
>Microsoft Online Support
>
>Get Secure! www.microsoft.com/security
>(This posting is provided "AS IS", with no warranties,

and confers no
>rights.)
>
>.
>

 
Reply With Quote
 
MSFT
Guest
Posts: n/a
 
      11-11-2003
Hi Derek,

Based on my test, this problem would occur when we add

TreeView1.Attributes.Add("oncheck", "DoCheck(this);")

in FormLoad. And it doesn't depend on what code we have in method DoCheck();

It seems the only work around is adding a hidden input in the form and set
selected node's value to it in DoCheck()

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
CheckBox Checked=false when checked in DataList yurps ASP .Net 1 02-29-2008 01:08 PM
debug="false" in web.config and <%@ debug="true" ...%> in aspx file => true or false? André ASP .Net 3 08-28-2006 12:02 PM
False positive, false intrusion, false alarm Nick Computer Security 3 04-26-2006 07:40 PM
Does true ^ true return false? Siemel Naran C++ 19 06-18-2004 11:06 AM



Advertisments