Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If statement in aspx page

I want to write a basic if statement on my site to display either item 1 or item 2 depending on if a variable is set to true.

I'm not too familiar with .NET and need a little help with the basic structure of how to get an if statement to work on the aspx page

like image 828
Brad Avatar asked Jun 17 '10 16:06

Brad


People also ask

How do you write if condition in ASPX?

To use C# (C# Script was initialized at 2015) on ASPX page you can make use the following syntax. Start Tag:- <% End tag:- %> Please make sure that all the C# code must reside inside this <%%> . <%@ Import Namespace="System.

What is <% in ASPX?

NET 4.0 - it is equivalent to HttpUtility. HtmlEncode(Response. Write()) . <%= is older and stands for Response.


2 Answers

if the purpose is to show or hide a part of the page then you can do the following things

1) wrap it in markup with

<% if(somecondition) { %>    some html <% } %> 

2) Wrap the parts in a Panel control and in codebehind use the if statement to set the Visible property of the Panel.

like image 162
Kris van der Mast Avatar answered Oct 01 '22 01:10

Kris van der Mast


Just use simple code

<% if(condition) {%>  html code  <% }  else  { %> html code <% } %> 
like image 42
عثمان غني Avatar answered Oct 01 '22 03:10

عثمان غني