Paul Kersey
Paul Kersey

Reputation: 21

strange bug with ASP.NET inline expression

If I enter the following mark-up in my aspx page, it builds with no errors:

<%if(_Competition == null && IsCompetitionPage)
         {%>

But!

<%else if(_Competition == null && IsCompetitionPage)
         {%>

gives the following error:

CS1525: Invalid expression term 'else'

Upvotes: 0

Views: 59

Answers (1)

Dave R.
Dave R.

Reputation: 7303

Remove any page content you've placed between the closing brace of the if statement and the start of the else.

For example, this will fail:

<%
  if (_Competition == null && IsCompetitionPage) {
%>
    <h2>Some content</h2>
<%}%>

INVALID CONTENT HERE

<%
  else if (!IsCompetitionPage) {
%>
    <h2>Some different content here</h2>
<%}%>

Removing 'INVALID CONTENT HERE' should fix the issue.

Upvotes: 1

Related Questions