views:

40

answers:

3

Today is the very first day I've ever even seen aspx, so, please bear with me...

Basically, I want to determine if a string is empty. If it is empty, then I don't want anything to output, if it's not, then I want to output the string itself.

<%= o_handler.renderDDesc()%> //This is the string itself... If this is empty, then I want I want nothing to print

I tried:

<%if (o_handler.renderDDesc().length() > 0) { %>
<%= o_handler.renderDDesc()%>
<%}%> 

But, that didn't seem to do anything. I didn't get an error, but it also didn't appear?

A: 
<%= !String.IsNullOrEmpty(o_handler.renderDDesc()) ? o_handler.renderDDesc() : ""%>
RedFilter
A: 

I would simply use a ternary operator as follows:

<%=( o_Handler.IsNullOrEmpty() ? string.Empty : o_handler.renderDDesc() ); %>
Nissan Fan
+1  A: 
<%

string desc = o_handler.renderDesc();

if (!String.IsNullOrEmpty(desc)) { 
Response.Write(desc);
}

%> 
Jason