Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want to write coding on the hyper link on click event can we castomise the hyperlink control
Posted

+5 for Solution 1

Another way is to use LinkButton

Regards.
 
Share this answer
 
Comments
bbirajdar 8-Jul-13 7:31am    
yes. LinkButton is the correct solution +5
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[^]
 
Share this answer
 
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.
XML
<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.

XML
<script type="text/javascript">
function confirmNavigation(){
    return confirm('Are you sure to navigate to other page?');
}
</script>



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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900