Alex Rivera | Logout

call javascript function on hyperlink click

Asked 2009-08-12T12:32:59.967
107

I am dynamically creating a hyperlink in the c# code behind file of ASP.NET. I need to call a JavaScript function on client click. how do i accomplish this?

Edit
Report

2 Answers

2

Use the onclick HTML attribute.

The onclick event handler captures a click event from the users’ mouse button on the element to which the onclick attribute is applied. This action usually results in a call to a script method such as a JavaScript function [...]

answered 2009-08-12T12:38:24.247
2

I would generally recommend using element.attachEvent (IE) or element.addEventListener (other browsers) over setting the onclick event directly as the latter will replace any existing event handlers for that element.

attachEvent / addEventListening allow multiple event handlers to be created.

answered 2009-08-12T13:14:09.787

Your Answer