Use if condition in ascx file

Khilen Maniyar picture Khilen Maniyar · Jul 28, 2011 · Viewed 24.5k times · Source

Hi, I want to use if condition in .ascx file. As shown below:

<%= if (value.equals("xyz")) {}  %>

as shown above, if i use like that. then i am getting error of "invalid expression if".

please guide me.

Answer

Darin Dimitrov picture Darin Dimitrov · Jul 28, 2011

Instead of <%= you should use <% (without the = sign):

<% if (value.equals("xyz")) { } %>

<%= is used when you want to output the result of the expression directly to the HTML.