SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
ASP.NET, VB.NET, Microsoft .NET Framework, Microsoft Visual Studio, Windows Forms, Controls and more Tutorials and Articles for Programmers


'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected.


While developing an ASP.NET Web Site, I got the following error message on my MS Visual Studio 2008 IDE.

Error 29 'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected.

Pointing to the page declaration tag in the .aspx source page.

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/ContentMaster.master" AutoEventWireup="false" CodeFile="UserAuthorization.aspx.vb" Inherits="Kodyaz.Web.UserAuthorization" %>

I have found that this exception is thrown by my error in using the Eval function.
I had placed the Eval function in a CommandArgument as below which is causing the .NET exception

CommandArgument="<% #Eval("UserFunctionId") %>"

And this is the correct usage.

CommandArgument='<%# Eval("UserFunctionId") %>'





The error "'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected." is directly related with a fault in "#" character usage.
So first stpe is checking the validity of directives like #Const, #ExternalSource, #If, #Else, #ElseIf, #End If, and #Region in your source codes.

Here is some notes from Microsoft MSDN

First be sure that the conditional compilation directives in the .NET codes are spelled correct
Then remove spaces between the # character and the directives if exists.



Visual Studio


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.