Highrad
Highrad

Reputation: 13

Hide Hyperlink if data is null

I want to hide the text "Apply Online!" below if the applicationURL is null.

<div class='sfitemShortTxtWrp'>
            <asp:HiddenField runat="server" ID="hdnApplyURL" Value='<%# Bind("ApplicationURL") %>' />        
            <a id="cmdApply" href="http://<%# Eval("ApplicationURL")%>" target="_blank" style="font-weight: bold">Apply Online!</a>                
        </div>

Thanks!

Upvotes: 0

Views: 1869

Answers (3)

Win
Win

Reputation: 62301

You can use CSS to hide the hyperlink.

<a id="cmdApply" href="http://<%# Eval("ApplicationURL")%>" 
   target="_blank" 
    style="font-weight: bold; <%# string.IsNullOrWhiteSpace(Eval("ApplicationURL").ToString()) ? " display: none": "" %>">
Apply Online!</a>

Upvotes: 1

Hackerman
Hackerman

Reputation: 12295

Jquery version:

var text = $("#cmdApply").attr("href");

if (text == "") {
    $("#cmdApply").hide();
}

Upvotes: 1

James Johnson
James Johnson

Reputation: 46077

It would be easier to use a HyperLink control:

<asp:HyperLink ID="cmdApply" runat="server" Target="_blank" NavigateUrl="..." Text="Apply Now" />

And in the code behind:

cmdApply.Visible = !string.IsNullOrEmpty(cmdApply.NavigateUrl);

Upvotes: 2

Related Questions