Link to home
Start Free TrialLog in
Avatar of EugeneC
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?


Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Are you sure its converted it to VB2005 ? It sounds like it's expecting C# syntax.
Avatar of EugeneC
EugeneC

ASKER

No I converted it from VB.NET to C#
In that case, it should say:

    <% if (Session["mode"] == "text") %>
Avatar of EugeneC

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

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>
Avatar of EugeneC

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>

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>
Avatar of EugeneC

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.
Avatar of EugeneC

ASKER

No its still a problem
Can you post the error EXACTLY as it appears in the build window ?
Avatar of EugeneC

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      
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial