Syntax error about imports having to precede declarations

I have the following code that is giving me an error:

Imports statements must precede declarations.  My imports is before my declarations.  Any idea what I'm doing wrong?

<%@ Page Language="VB" %>
<script runat="server">

    Imports Microsoft.Win32
    dim Accountskey as registrykey
    Accountskey = Registry.CurrentUser.OpenSubKey("Software\VB and VBA Program Settings\Mailgov (Redirector)\AccountSettings", False)
        for each strAccount in Accountskey.getvaluenames()
            strAccounts = strAccounts & strAccount
        next
        Label1.text = strAccounts

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        Done
        <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        <asp:Label id="Label1" runat="server">Label</asp:Label>
        <!-- Insert content here -->
    </form>
</body>
</html>
LVL 1
jodygliddenAsked:
Who is Participating?
 
Timbo87Commented:
Importing namespaces is possible even when using interspersed ASP.NET code.

Add this under your @Page directive.
<% @Import Namespace="Microsoft.Win32" %>

Arthur,

As far as I know, there is nothing code-behind can do that embedded code cannot do. I use code-behind myself, but embedded code is just as powerful.
0
 
Arthur_WoodCommented:
why are you writing the VB.NET code in your aspx page,and not using the CodeBehind.  The problem is that the code as you have it here, is actually being seen, by the JIT compiler, as if it were following the implied declarations of the controls on your page, and that is sees as creasting the 'error' that you are seeing.

ASP.NET does NOT support coding as you have it here, which is the older ASP style, using embedded VBScript.  In fact, you cannot embed VBScript in the ASPX page, in any fashion.  

ASP.NET is a completely DIFFERENT style of web development, and you would be VERY wise to TOTALLY FORGET (yes FORGET) everything your ever knew (or thought you knew) about ASP development, becuase it has ABSOLUTELY no relevance to ASP.NET development.  The two are as different as Night and Day - actually they are more different - say like Cats and Airplanes.

AW
0
 
jodygliddenAuthor Commented:
That's what I've read as well.  Also, Timbo fixed my bug.  Thanks.
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.