Reply
Alert before link is clicked
Old 03-22-2005, 08:42 AM Alert before link is clicked
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
Is there a way to attach a bit of javascript to OnMouseUp of a link (Can't use OnClick cos it's an ASP.NET LinkButton control) to ask the user if they're sure they want to continue?
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
When You Register, These Ads Go Away!
     
Old 03-22-2005, 10:48 AM
Rufo's Avatar
Extreme Talker

Posts: 173
I think that by the time the OnMouseUp event is fired, it is too late to stop the request (unless there is a command which does the equivalent of clicking the 'stop' button on the browser)

Rufo
__________________
mp3blog.us
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 03-22-2005, 11:36 AM
Kaiman's Avatar
Extreme Talker

Posts: 237
Can you write an alert function that combines with the ASP.NET onclick event?

Also, if its just one link, how about using the onmouseover event?

Kaiman

Storm King Design
Kaiman is offline
Reply With Quote
View Public Profile
 
Old 03-22-2005, 03:50 PM
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
I thought OnClick didn't fire until OnMouseUp did? Like, OnClick is actually a combo of both OnMouseDown and OnMouseUp happening on the same element. If that's true, OnMouseUp should work...

No idea about combining it with ASP.NET... the OnClick attribute of the asp:LinkButton component needs to have the name of an ASP.NET handler in it or it will complain. There might be a way to sneak it in after it's been rendered but no idea how. Come to think of it, I could use javascript to attach the events... provided ASP.NET generates predictable IDs.

Suppose I could use the OnClick event naturally, what would the code be?
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 03-22-2005, 03:58 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Unicode and Character Sets
Posts: 3,108
Location: Toronto, Ontario
HTML Code:
<a href="http://google.com" onclick="return confirm('Are you sure you want to continue?')">Link</a>
onclick is fired after both onmousedown and onmouseup have fired, so you could use either one I suppose. onclick is in response to a true click, (ie. button down - button up), while onmousedown is only in response to the down click, and onmouseup to the up. Thus, if a user clicks, holds, and then moves the pointer away from the object, the onclick event will not fire.
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 03-22-2005, 05:26 PM
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
OnMouseUp is fine. Only problem is if someone clicks off the link, moves onto the link, then releases, it will ask for a confirmation and then not do anything. I'm willing to risk that.

Chroder, that's exactly what I need except... it doesn't work. The link always fires.. that is in Firefox & Opera - works fine in IE... Guess I could make it an IE Only thing..
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad

Last edited by Minaki : 03-22-2005 at 05:29 PM.
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 03-22-2005, 06:40 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Unicode and Character Sets
Posts: 3,108
Location: Toronto, Ontario
onclick works, onmousedown or up does not.

Why not just use ASP.NET to add the onclick to your link? Something like this, perhaps:

Code:
<script language="C#" runat="server">
mylink.Attributes.Add("onclick", "return confirm('Are you sure you want to continue?')");
</script>
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 03-23-2005, 04:35 AM
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
Didn't know you could do that. I'll try it in a bit...

OK it works, but not really - because I have the LinkButton in a DataGrid. If I move it out of the datagrid it's fine, but inside the datagrid it I get "Name 'cmdCancel' is not declared. ". Guess I'lkl have to read up on embedding controls in DataGrids... sure I've done something like this before so shouldn't be too hard...
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad

Last edited by Minaki : 03-23-2005 at 05:02 AM.
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to Alert before link is clicked
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16288 seconds with 13 queries