Question Variable not declared?


New member
Jan 12, 2015
Programming Experience
I have a problem that?s driving me crazy. I apologize if this is beginner stuff, but I don't know what to do.

It's an ASP.NET Web Application. I'm using VS2013 Pro. I have a Web Form, WebForm1.aspx. It looks like this:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
<form id="form1" runat="server">

The code behind, WebForm1.aspx.vb, looks like this:

Public Class WebForm1
Inherits System.Web.UI.Page
Public MyVar = "Blah Blah"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class

And the error message I'm getting is: 'MyVar' is not declared. It may be inaccessible due to its protection level. The error is in WebForm1.aspx.

Most maddening, sometimes it works, sometimes I get the error message.

What am I doing wrong?
Top Bottom