Reputation: 34257
ASP.NET
<asp:HyperLink id="hyp" runat="server">TEXT</asp:HyperLink>
MARKUP
<a>TEXT</a>
VB.NET
If hyp.NavigateURL = "" Then
'do stuff
End If
QUESTION
How to check if an anchor tag has a href attribute from code behind?
Upvotes: 0
Views: 1833
Reputation:
If you create a hyperlink
using asp tags
<asp:HyperLink id="aspHyp" runat ="server" ></asp:HyperLink>
Then you can check whether the href is blank or not using
If aspHyp.NavigateUrl = "" Then
MsgBox("Href is blank!")
End If
If you create a hyperlink using <a>
<a id="hyp" runat ="server">TEXT</a>
Then you can check whether the href is blank or not using
If hyp.HRef = "" Then
MsgBox("Href is blank!")
End If
Upvotes: 1
Reputation:
in html you can check by this
<%
if (your condition) {%>
tags to show...
<%} %>
and when you want to do this in code behind, you should use this
if(hyp.NavigateUrl = "")
{ write your code here .... }
Upvotes: 0
Reputation: 572
Are you missing " around id="hyp" or was that just a typo?
You should be able to check if the NavigateUrl on a Hyperlink is an empty string, like you're doing.
The URL to navigate to when a hyperlink in a HyperLinkField is clicked. The default is an empty string (""), which indicates that this property is not set.
Upvotes: 1