Search code examples
asp.netif-statementascx

Use if condition in ascx file


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.


Solution

  • 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.