'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.
