Question Variable not declared?

azra

New member
Joined
Jan 12, 2015
Messages
1
Programming Experience
Beginner
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="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%
Response.Write(MyVar)
%>
</div>
</form>
</body>
</html>



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