EugeneC
asked on
Embedded statement cannot be a declaration or labeled statement
<% if session("mode")="text" then %>
I’ve converted a vb.net 2003 web project to 2005 using a third party utility. Seems to have worked but I am getting the following errors
The session keyword is highlighted with the error
‘(‘ expected
And the “then” keyword has an error of
‘)’ expected.
Also the error states
“Embedded statement cannot be a declaration or labeled statement “
Any ideas?
Are you sure its converted it to VB2005 ? It sounds like it's expecting C# syntax.
ASKER
No I converted it from VB.NET to C#
In that case, it should say:
<% if (Session["mode"] == "text") %>
<% if (Session["mode"] == "text") %>
ASKER
HI
Thanks for that but I am still getting errors as follows:
<HEAD>
<title>Neighbourhood Information Service</title>
<% if (session["mode"]=="text") then %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<%else%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<%end if%>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
I get ; expected at the first then
AND
; expected at the last if
Thanks for that but I am still getting errors as follows:
<HEAD>
<title>Neighbourhood Information Service</title>
<% if (session["mode"]=="text") then %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<%else%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<%end if%>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
I get ; expected at the first then
AND
; expected at the last if
You don't need the Then or End If:
<HEAD>
<title>Neighbourhood Information Service</title>
<% if (session["mode"]=="text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else { %>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% } %>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
<HEAD>
<title>Neighbourhood Information Service</title>
<% if (session["mode"]=="text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else { %>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% } %>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
ASKER
Hi I am getting '(' expected on the first IF
<HEAD>
<title>Neighbourhood Information Service</title>
<% if (session["mode"] == "text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% }%>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
<HEAD>
<title>Neighbourhood Information Service</title>
<% if (session["mode"] == "text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% }%>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
Try:
<HEAD>
<title>Neighbourhood Information Service</title>
<% if ((string)Session["mode"] == "text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% }%>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
<HEAD>
<title>Neighbourhood Information Service</title>
<% if ((string)Session["mode"] == "text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% }%>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
ASKER
Sorry but I'm getting invalid expression term ELSE
<HEAD>
<title>Neighbourhood Information Service</title>
<% if ((string)Session["mode"] == "text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% }else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% } %>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
</HEAD>
Well theres nothing wrong with the C# block. Which means there is either something in your css that is disrupting things, or its not this block thats causing the problem.
Temporarily remove your LINK tags and see if the error goes away.
ASKER
No its still a problem
Can you post the error EXACTLY as it appears in the build window ?
ASKER
HI I am making progress but now I am getting
<% if (session["mode"]=="text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% } %>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
The name 'session' does not exist in the current context
<% if (session["mode"]=="text") { %>
<LINK media="screen" href="css/text.css" type="text/css" rel="stylesheet">
<% } else {%>
<LINK media="screen" href="css/layout.css" type="text/css" rel="stylesheet">
<LINK media="screen" href="css/nis.css" type="text/css" rel="stylesheet">
<% } %>
<LINK media="print" href="css/print.css" type="text/css" rel="stylesheet">
The name 'session' does not exist in the current context
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.