Treeview node, add confirm javascript?

  • Thread starter Thread starter tfsmag
  • Start date Start date
T

tfsmag

Okay, I have a project management app i'm writing and in the left hand
menu i have a treeview control that is populated with each project...
in child nodes under each project node I have an "edit" and a "delete"
node. I have the functionality of the edit and delete working fine, my
issue is now however that I cannot seem to find a way to add an
"onclick" event that fires a confirm box. I've tried this method..

treenode.Text = "<a href=""javascript:confirm('confirm text') return
true;"">text</a>"

and that fires a confirm, but does nothing when i click on "ok", in
other words it doesn't delete the project when i confirm.

Can anyone lend a hand here? Thanks in advance!

- Jeff
 
Hi,
Okay, I have a project management app i'm writing and in the left hand
menu i have a treeview control that is populated with each project...
in child nodes under each project node I have an "edit" and a "delete"
node. I have the functionality of the edit and delete working fine, my
issue is now however that I cannot seem to find a way to add an
"onclick" event that fires a confirm box. I've tried this method..

treenode.Text = "<a href=""javascript:confirm('confirm text') return
true;"">text</a>"

and that fires a confirm, but does nothing when i click on "ok", in
other words it doesn't delete the project when i confirm.

First, you should never ever use the javascript: pseudo protocol in a
HREF. That is known to cause problems. Check comp.lang.javascript on
Google News for details.

Second, of course the code above does nothing. You ignore the return
value of the "confirm" function. confirm() returns true if OK was
clicked, false otherwise.

Finally, you return true in your HREF, but that doesn't help anything.
What do you want to achieve if the user clicks OK? Call a URL? If yes,
that should be:

treenode.Text = "<a href=""aUrl.html"" onclick=""return confirm('confirm
text');"">text</a>"

Sorry, I don't do VB.NET, so I am not totally sure if the syntax is correct.

HTH,
Laurent
 
thanks laurent, i'm pretty bad with javascript... i'll try your code
out and see how it goes.

cheers,
Jeff
 
nope.. that still didn't work... when placing javascript inside of the
text attributes, it is overriding the treenode_click event with what's
in the javscripts onclick event. Anyone else have any ideas?
 
Okay i finally figured it out... Here is how i got it to work

Dim deletenode As New TreeNode("<span onclick=""javascript:confirm('Are
you sure you want to delete " & dr("ProjectName") &
"?');"">Delete</span>", "0" & dr("ProjectID"))

This made it work correctly and still fire the SelectedNodeChanged
event. I had to use a <span> tag because when i used a normal <a href>
it would override the SelectedNodeChanged event. Simple solution it
seems, but man did it take me awhile to figure out!
 
Back
Top