You may assume that the HyperLink control is the way to go if you want to create a linked text. However, the LinkButton seems to offer a better solution when it comes to linking to a popup window.
<asp:HyperLink
ID="MyHyperlink"
runat="server"
NavigateUrl="www.hotmail.com"
Target="_blank">Hotmail Link</asp:HyperLink> seems correct in first look.
But what if you want to set the properties of the popup window? You use onclick (html default attribute).
<asp:HyperLink
ID="MyHyperlink"
runat="server"
onclick="javascript:window.open('www.hotmail.com','','scrollbars=yes,menubar=no,height=450,width=605,resizable=yes,toolbar=no,location=no,status=no">
Hotmail Link</asp:HyperLink>
To define the onclick property dynamically, use MyHyperlink.Attributes["onclick"] = "…"
However when you run the aspx page you will realize that the hyperlink is no longer a hyperlink! (i.e. not underlined and cannot be clicked). This is because if NavigationURL is not set, then it will assume that it is merely a Literal.
Maybe you think this would work: <asp:HyperLink
ID="MyHyperlink"
runat="server"
onclick="…" NavigateUrl="#">Hotmail Link</asp:HyperLink>
When you run the aspx page, the hyperlink returns, but because all your hyperlinks are set to #, they will be considered as "visited" although you may not have visited www.hotmail.com.
A LinkButton makes more sense, in this case, because it gives you your hyperlink AND you can set properties of the popup window.
<asp:LinkButton
ID="LinkButton1"
runat="server"
OnClick="…">LinkButton</asp:LinkButton>
* You may have been misled to think a LinkButton will return you a button-looking thing with underlined-text. But try this out! If it doesn't work, you can always set the properties!
No comments:
Post a Comment