Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i want to write coding on the hyper link on click event can we castomise the hyperlink control
Posted 7-Feb-11 22:08pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use client side onclick of a hyperlink. Use Attributes collection as in:
myHyperlink.Attributes.Add ("onClick", "alert('Hello');");
 

For server side, similar discussions here:
Override default hyperlink action with onClick[^]
Need a hyperlink "onclick" event to run server-side[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

+5 for Solution 1
 
Another way is to use LinkButton
 
Regards.
  Permalink  
Comments
aspnet -i at 8-Jul-13 7:31am
   
yes. LinkButton is the correct solution +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a>[<a href="" target="_blank"></a>][]&&&&&&>>>><<<<
  Permalink  
Comments
Debashree Ghosh at 11-Mar-13 7:17am
   
How to write a code in asp.net when you take the cursor to a link it will show a message automatically?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

In ASP.Net you can attach the onclick event to Hyperlink control in two ways. First way is to add and assign the value at the time of designing by adding the onclick property as an attribute of HyperLink control in the HTML markup code block.
<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl="Default2.aspx"
onclick="return confirm('Are you sure?');">
Hyperlink
</asp:HyperLink>
 
The Second way is to add the onclick attribute programmatically at the server side.
HyperLink1.Attributes.Add("onclick", "return confirm('Are you sure to navigate to other page?');");
 
In the example below a javascript function will show a confirm message with Ok and cancel button. If the user will click the cancel button then it will return false otherwise true.
 
<script type="text/javascript">
function confirmNavigation(){
    return confirm('Are you sure to navigate to other page?');
}
</script>
 

<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl="Default2.aspx"
onclick="return confirmNavigation();">
Hyperlink
</asp:HyperLink>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 645
1 OriginalGriff 560
2 CPallini 294
3 Peter Leow 185
4 RyanDev 146
0 OriginalGriff 6,034
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,129
3 Maciej Los 3,079
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100