?
Solved

Embedded statement cannot be a declaration or labeled statement

Posted on 2006-05-10
14
Medium Priority
?
551 Views
Last Modified: 2012-05-05




<% 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?


0
Comment
Question by:EugeneC
  • 8
  • 6
14 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647213
Are you sure its converted it to VB2005 ? It sounds like it's expecting C# syntax.
0
 

Author Comment

by:EugeneC
ID: 16647228
No I converted it from VB.NET to C#
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647234
In that case, it should say:

    <% if (Session["mode"] == "text") %>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:EugeneC
ID: 16647322
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647334
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
 

Author Comment

by:EugeneC
ID: 16647399
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647438
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
 

Author Comment

by:EugeneC
ID: 16647484

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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647511
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647515
Temporarily remove your LINK tags and see if the error goes away.
0
 

Author Comment

by:EugeneC
ID: 16647654
No its still a problem
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16647708
Can you post the error EXACTLY as it appears in the build window ?
0
 

Author Comment

by:EugeneC
ID: 16648453
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
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 16648466
Session needs an uppercase S at the start. C# is case-sensitive.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question