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?


EugeneCAsked:
Who is Participating?
 
Carl TawnSystems and Integration DeveloperCommented:
Session needs an uppercase S at the start. C# is case-sensitive.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Are you sure its converted it to VB2005 ? It sounds like it's expecting C# syntax.
0
 
EugeneCAuthor Commented:
No I converted it from VB.NET to C#
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Carl TawnSystems and Integration DeveloperCommented:
In that case, it should say:

    <% if (Session["mode"] == "text") %>
0
 
EugeneCAuthor Commented:
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

0
 
Carl TawnSystems and Integration DeveloperCommented:
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>
0
 
EugeneCAuthor Commented:
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>

0
 
Carl TawnSystems and Integration DeveloperCommented:
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>
0
 
EugeneCAuthor Commented:

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>
0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Temporarily remove your LINK tags and see if the error goes away.
0
 
EugeneCAuthor Commented:
No its still a problem
0
 
Carl TawnSystems and Integration DeveloperCommented:
Can you post the error EXACTLY as it appears in the build window ?
0
 
EugeneCAuthor Commented:
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      
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.