Use if condition in ascx file

Viewed 27145

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.

3 Answers

Above answers can not be used for boolean atributes such as "Visible". Instead put this code in the BindData() function.

if (condition) {
    this.pnlMyPanel.Visible = true;
} else {
    this.pnlMyPanel.Visible = false;
}

If you don't tipically use BindData(), put it in Page_Load under

if (!this.IsPostBack) {}

block.

Related