简体   繁体   中英

How can I add some conditional Javascript to my Asp Hyperlink's NavigateUrl property?

So I have a Hyperlink on my asp.net page. When the person clicks that link, it carries out some action. Now I want to be able to add a javascript alert (confirm, actually) as to whether the user is SURE he/she wants to carry out the action? If yes, then carry out the action, otherwise do nothing. How do I do this?

My current code just has a link to the action:

Link1.NavigateUrl = "./Actions.aspx?action=abort&job=" + JobID;

I'm not at my development environment to test this out, but something like this should work for you:

Link1.NavigateUrl = "./Actions.aspx?action=abort&job=" + JobID;
Link1.Attributes["onclick"] = "return confirm('Are you sure?');";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM