0

How can I enter this URL into a HyperLink ASP.NET Control ?

<a href="https://plus.google.com/share?url={URL}" 
   onclick="javascript:window.open(this.href,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
    <img src="https://www.gstatic.com/images/icons/gplus-64.png" alt="Share on Google+"/>
</a>
4
  • Are you having problems with the {URL} bit? Commented Jan 21, 2013 at 21:17
  • no, I don't know how to include the javascript onclick Commented Jan 21, 2013 at 21:18
  • well thats not the URL... that is the onclick javascript Commented Jan 21, 2013 at 21:19
  • thanks for editing the title - was misleading ;) Commented Jan 21, 2013 at 21:26

2 Answers 2

3

Just use onclick. Any properties that are not recognized by ASP.Net are passed as-is.

<asp:HyperLink ID="HyperLink1" runat="Server"
    NavigateUrl="https://plus.google.com/share?url={URL}"
    onclick="javascript:window.open(this.href, '',
      'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
      return false;">
  ...
</asp:HyperLink>

In general, if you don't need server-side access to a control, I wouldn't recommend converting them to server-side because it adds extra unnecessary processing to the server.

Sign up to request clarification or add additional context in comments.

Comments

1

To add it in the declarative syntax just add it i.e.

<asp:HyperLink 
    runat="server" 
    ID="theLink" 
    onclick="javascript:window.open(this.href, '','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
  return false;">
</asp:HyperLink>

You must note that OnClick (which is event binding for ASP.NET and the lowercase version onclick are NOT the same)

If you want to do it in code behind then you can do it via the WebControl.Attributes array ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.