Handling oncheck event of Treeview web control on the client side

Handling oncheck event of Treeview web control on the client side

Post by Mar » Thu, 07 Feb 2002 15:01:26



I am using the Treeview Web Control and I am having a rough time
trying to figure out how to handle the "oncheck" event on the client
side. I created a script like so:

<script for="TreeView1" event="oncheck">
   ...
</script>

When the oncheck event fires, this script does run, but how do I get a
reference to the node that was "checked"? I can't really seem to get a
reference to the treeview control at all in client side script.

m

 
 
 

Handling oncheck event of Treeview web control on the client side

Post by MS » Fri, 08 Feb 2002 12:07:16



Quote:> I am using the Treeview Web Control and I am having a rough time
> trying to figure out how to handle the "oncheck" event on the client
> side. I created a script like so:

> <script for="TreeView1" event="oncheck">
>    ...
> </script>

> When the oncheck event fires, this script does run, but how do I get a
> reference to the node that was "checked"? I can't really seem to get a
> reference to the treeview control at all in client side script.

Hi,

What does window.event.srcElement return?

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.

 
 
 

Handling oncheck event of Treeview web control on the client side

Post by Mark Pitma » Fri, 08 Feb 2002 13:43:19


It returns a reference to my treeview control. That's a start! Now the
question is, how can I determine which node was checked? I have checkboxes
turned on for all the nodes, my end goal is to be able to check a box and
have all the nodes under it get checked also.

m





> > I am using the Treeview Web Control and I am having a rough time
> > trying to figure out how to handle the "oncheck" event on the client
> > side. I created a script like so:

> > <script for="TreeView1" event="oncheck">
> >    ...
> > </script>

> > When the oncheck event fires, this script does run, but how do I get a
> > reference to the node that was "checked"? I can't really seem to get a
> > reference to the treeview control at all in client side script.

> Hi,

> What does window.event.srcElement return?

> Peter

> --

> Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
> Please post all questions to the group. Thanks.

 
 
 

Handling oncheck event of Treeview web control on the client side

Post by MS » Sat, 09 Feb 2002 09:40:08



Quote:> It returns a reference to my treeview control. That's a start! Now the
> question is, how can I determine which node was checked? I have checkboxes
> turned on for all the nodes, my end goal is to be able to check a box and
> have all the nodes under it get checked also.

Hmmm, I wonder why it's not the checkbox itself. Maybe it's a behaviour.

Can you post a *very basic* ASP .NET page with a TreeView on it (single-file
please; code behind is messy) and I'll see what HTML it generates.

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.

 
 
 

Handling oncheck event of Treeview web control on the client side

Post by Mark Pitma » Tue, 12 Feb 2002 14:50:31






> > It returns a reference to my treeview control. That's a start! Now the
> > question is, how can I determine which node was checked? I have
checkboxes
> > turned on for all the nodes, my end goal is to be able to check a box
and
> > have all the nodes under it get checked also.

> Hmmm, I wonder why it's not the checkbox itself. Maybe it's a behaviour.

> Can you post a *very basic* ASP .NET page with a TreeView on it
(single-file
> please; code behind is messy) and I'll see what HTML it generates.

> Peter

> --

> Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
> Please post all questions to the group. Thanks.

OK, I won't post the whole page. First, you have to put this at the top of
your page:


Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.116, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" %>

Then a script to handle the event:
<script for="TreeView1" event="oncheck">
alert(window.event.srcElement);
</script>

Then in the body of the page, preferably inside a form:

<iewc:treeview name="TreeView1" id="TreeView1" runat="server"
TreeNodeSrc="music.xml"></iewc:treeview>

my music.xml file looks something like this:

<TREENODES>
 <treenode text="Bauhaus" checkbox="true">
<treenode text="Crackle" checkbox="true"><treenode text="01-Double Dare"
path="D:\\WMA\\Bauhaus\\Crackle\\01-Double Dare.wma"
checkbox="true"></treenode>
   <treenode text="02-In the Flat Field"
path="D:\\WMA\\Bauhaus\\Crackle\\02-In the Flat Field.wma"
checkbox="true"></treenode>
   <treenode text="03-The Passion of Lovers"
path="D:\\WMA\\Bauhaus\\Crackle\\03-The Passion of Lovers.wma"
checkbox="true"></treenode>
   <treenode text="04-Bela Lugosi's Dead"
path="D:\\WMA\\Bauhaus\\Crackle\\04-Bela Lugosi%27s Dead.wma"
checkbox="true"></treenode>
   <treenode text="05-The Sanity Assassin"
path="D:\\WMA\\Bauhaus\\Crackle\\05-The Sanity Assassin.wma"
checkbox="true"></treenode>
   <treenode text="06-She's in Parties [Edit]"
path="D:\\WMA\\Bauhaus\\Crackle\\06-She%27s in Parties [Edit].wma"
checkbox="true"></treenode>
   <treenode text="07-Silent Hedges"
path="D:\\WMA\\Bauhaus\\Crackle\\07-Silent Hedges.wma"
checkbox="true"></treenode>
   <treenode text="08-Hollow Hills"
path="D:\\WMA\\Bauhaus\\Crackle\\08-Hollow Hills.wma"
checkbox="true"></treenode>
   <treenode text="09-Mask" path="D:\\WMA\\Bauhaus\\Crackle\\09-Mask.wma"
checkbox="true"></treenode>
   <treenode text="10-Kick in the Eye [Alternate Version]"
path="D:\\WMA\\Bauhaus\\Crackle\\10-Kick in the Eye [Alternate Version].wma"
checkbox="true"></treenode>
   <treenode text="11-Ziggy Stardust"
path="D:\\WMA\\Bauhaus\\Crackle\\11-Ziggy Stardust.wma"
checkbox="true"></treenode>
   <treenode text="12-Dark Entries" path="D:\\WMA\\Bauhaus\\Crackle\\12-Dark
Entries.wma" checkbox="true"></treenode>
   <treenode text="13-Terror Couple Kill Colonel"
path="D:\\WMA\\Bauhaus\\Crackle\\13-Terror Couple Kill Colonel.wma"
checkbox="true"></treenode>
   <treenode text="14-Spirit [Alternate Version]"
path="D:\\WMA\\Bauhaus\\Crackle\\14-Spirit [Alternate Version].wma"
checkbox="true"></treenode>
   <treenode text="15-Burning from the Inside"
path="D:\\WMA\\Bauhaus\\Crackle\\15-Burning from the Inside.wma"
checkbox="true"></treenode>
   <treenode text="16-Crowds"
path="D:\\WMA\\Bauhaus\\Crackle\\16-Crowds.wma" checkbox="true"></treenode>
  </treenode>
 </treenode>
</TREENODES>

It is an IE behavior. When you handle the event server-side, it gives you
the index of the node that was checked. Client-side, it seems to give you
just the treeview itself. Thanks for looking at this!

m

 
 
 

Handling oncheck event of Treeview web control on the client side

Post by MS » Sun, 17 Feb 2002 11:17:50



Quote:> OK, I won't post the whole page. First, you have to put this at the top of
> your page:

Hey,

Sorry for the delay. I had to install the controls and then my machine
bluescreened because I was still running an internal evaluation copy of
Windows XP, and the evaluation period ended... oops! So I had to reinstall
that.

But anyways, the answer is that you can use:

    window.event.srcElement.clickedNodeIndex

I found this out with the following code, added to your page:

<script for="TreeView1" event="oncheck">
var s = ""
var ev = window.event.srcElement
for (var p in ev)
{
  if ((p.indexOf("on") == 0) || (p.indexOf("HTML") > 0))
    continue

  s += "ev[" + p + "] = " + ev[p] + "\r\n"

Quote:}

document.all.baz.innerText = s//alert(s);
</script>

<pre id="baz"
</pre>

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.

 
 
 

Handling oncheck event of Treeview web control on the client side

Post by Mark Pitma » Thu, 21 Feb 2002 08:45:48


Thanks, that was exactly what I was looking for!

m





> > OK, I won't post the whole page. First, you have to put this at the top
of
> > your page:

> Hey,

> Sorry for the delay. I had to install the controls and then my machine
> bluescreened because I was still running an internal evaluation copy of
> Windows XP, and the evaluation period ended... oops! So I had to reinstall
> that.

> But anyways, the answer is that you can use:

>     window.event.srcElement.clickedNodeIndex

> I found this out with the following code, added to your page:

> <script for="TreeView1" event="oncheck">
> var s = ""
> var ev = window.event.srcElement
> for (var p in ev)
> {
>   if ((p.indexOf("on") == 0) || (p.indexOf("HTML") > 0))
>     continue

>   s += "ev[" + p + "] = " + ev[p] + "\r\n"
> }
> document.all.baz.innerText = s//alert(s);
> </script>

> <pre id="baz"
> </pre>

> Peter

> --

> Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
> Please post all questions to the group. Thanks.