How to call javascript from asp.net hyperlink control

I just want to call the JavaScript function from the asp.net im hyperlink using http://orangoo.com/labs/GreyBox/ my requirement is to show a thumbnail of the hyperlink and show the full image by clicking. Should I use a different control? my code is below:

<asp:HyperLink ID="Hyperlink" runat="server" CssClass="Screenshot" ImageUrl="App_Themes/White/Images/thmb_screenshot_1.png" NavigateUrl="App_Themes/White/Images/screenshot_1.png" ToolTip="screenshot 1" /> <script language="javascript" type="text/javascript"> //Greybox Image popup window function OpenImage(url) { var caption = "Home"; return GB_showImage(caption, url) } </script> 

how can i use

 onclick="OpenImage(this.src); or OnClientClick="OpenImage(this.src); 
+4
source share
4 answers

If you use LinkButton , you can use the OnClientClick property to execute the JavaScript function. Using the HyperLink control, you can use the NavigateUrl property as follows:

 <asp:HyperLink ID="Link1" runat="server" Text="Click Me!" NavigateUrl="javascript:OpenImage('App_Themes/White/Images/thmb_screenshot_1.png');"> </asp:HyperLink> 

Here is an article that talks about this:
http://gchandra.wordpress.com/2007/09/27/call-javascript-function-inside/

+6
source

I know this is old, but who cares, just add onclick and it will work fine. An additional attribute (even if it is not displayed in intellisense) will pass until the markup is displayed.

  <asp:HyperLink ID="HyperLink4" runat="server" onclick="logDownload();" NavigateUrl="~/download/Sample-Icons.zip">Download Icons</asp:HyperLink> 
+11
source

I know this is out of date, but for those who want to do this on the server side, and not through the markup, you can do it.

 var hyperLink = new HyperLink { Text = "Display text", ID = "hyperlinkId"}; hyperLink.Attributes.Add("onclick", "javascriptMethod()"); 
+3
source

It looks like you're mostly there, what's wrong with that?

 <asp:HyperLink ID="Hyperlink" runat="server" OnClientClick="OpenImage(this.src)" /> 
-3
source

Source: https://habr.com/ru/post/1411814/


All Articles