Skip to content Skip to sidebar Skip to footer

How Do I Conditionally Control The Visibility Of A Control In ASP.NET?

I've got an asp:Image. I want this control to display, only if <%#Eval('Image')%> is not null. I do not know how to write this conditional statement. What I'm trying to say i

Solution 1:

You can bind the Visible property of your control to the expression and call DataBind() while the page is loading:

<asp:Image runat="server" id="image" Visible='<%#Eval("Image") != null %>' />

If you are not using server controls and want to show/hide simple markup, you can simply enclose it in an if statement:

<% if ( condition ) { %>
    <img src='<%= linkToImageSource %>' />
<% } %>

Post a Comment for "How Do I Conditionally Control The Visibility Of A Control In ASP.NET?"