0

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;
Freakishly
  • 1,533
  • 5
  • 32
  • 61

1 Answers1

1

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?');";
Jason Whitted
  • 4,059
  • 1
  • 16
  • 16
  • Thanks Jason. If I leave the NavigateUrl as it is, and add the onclick attribute, I get the following error: "Server error in application--The resource cannot be found, HTTP 404" which is BS cuz if I don't add the onclick line, everything works as expected. "The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly" It's talking about Actions.aspx, which definitely exists. – Freakishly Dec 21 '12 at 03:50
  • Could I get you to load the page, view source, find the hyperlink tag and paste the HTML here for me to review? It may just be a simple syntax issue. – Jason Whitted Dec 21 '12 at 03:53
  • Are the `'` in the `onclick` and the `&` in the `href` artifacts of your copy & paste? Or are they actually escaped like that when you view source? – Jason Whitted Dec 21 '12 at 20:10
  • Nevermind, I realized the actual Actions file wasn't checked into source, and hence the 404. Thanks Jason :) – Freakishly Dec 21 '12 at 22:06