469,964 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Treeview node, add confirm javascript?

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

Aug 25 '06 #1
4 9801
Hi,

tfsmag wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 25 '06 #2
thanks laurent, i'm pretty bad with javascript... i'll try your code
out and see how it goes.

cheers,
Jeff

Laurent Bugnion wrote:
Hi,

tfsmag wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 25 '06 #3
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?
tfsmag wrote:
thanks laurent, i'm pretty bad with javascript... i'll try your code
out and see how it goes.

cheers,
Jeff

Laurent Bugnion wrote:
Hi,

tfsmag wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 27 '06 #4
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 <spantag 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!
tfsmag wrote:
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?
tfsmag wrote:
thanks laurent, i'm pretty bad with javascript... i'll try your code
out and see how it goes.

cheers,
Jeff

Laurent Bugnion wrote:
Hi,
>
tfsmag wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by JustinG | last post: by
6 posts views Thread by Tim | last post: by
4 posts views Thread by Yavuz Bogazci | last post: by
2 posts views Thread by Christian Rühl | last post: by
3 posts views Thread by Michael_Burgess | last post: by
1 post views Thread by R.A.F. | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.