DreamTeK
DreamTeK

Reputation: 34257

Check if an asp:Hyperlink href is empty? asp.net

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

Answers (3)

user3972104
user3972104

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

user1896357
user1896357

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

auo
auo

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.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.navigateurl(v=vs.110).aspx

Upvotes: 1

Related Questions