By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Treeview node, add confirm javascript?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.