Use if condition in ascx file
This is because the expression does not evaluate the string that can be included in the markup, so note <%= cannot be used. You can do this with a conditional statement:
<%= condition ? "value if true" : "value if false" %> Or you can insert a block of code using this notation:
<% if (value.equals("xyz")) { } %> Just remember that then you need Response.Write any output you want in braces. This is not a good practice - try to avoid logic in your markup.
The above answers cannot be used for boolean attributes such as Visible. Instead, enter this code in the BindData () function.
if (condition) { this.pnlMyPanel.Visible = true; } else { this.pnlMyPanel.Visible = false; } If you are not using the BindData () font, do not put it in Page_Load in
if (!this.IsPostBack) {} block.