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
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.
NET 4.0 - it is equivalent to HttpUtility. HtmlEncode(Response. Write()) . <%= is older and stands for Response.
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.
Just use simple code
<% if(condition) {%> html code <% } else { %> html code <% } %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With