Question : Can't access variable in code behind page

HI,

I have a project I'm working on, and I want to simply change a txtlabel on a page (which will be shown in a contentplaceholder). But for some magical reason, I can't access it.

Why do they make it so difficult?!

Here is the code
default.aspx
1:
2:
3:
4:
5:
6:
<%@ Page Language="vb" title="Homepage" MasterPageFile="~/MasterPage.Master" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>

<asp:Content ID="ContentHomePage" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>    This is the HomePage
    <asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Content>


Default.aspx.vb
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Public Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Sub Button1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.text = "hi"
    End Sub
End Class


I get 2 errors in the page behind:
1-
Error      97      Handles clause requires a WithEvents variable defined in the containing type or one of its base types.      C:\***\WebApplication1\WebApplication1\Default.aspx.vb      7      94      C:\...\WebApplication1\


2-
Error      98      Name 'Label1' is not declared.      C:\***\WebApplication1\WebApplication1\Default.aspx.vb      8      9      C:\...\WebApplication1\



When I check other examples, you don't have to declare any labels again in the code behind...What am I doing wrong?

Answer : Can't access variable in code behind page

Well, as I mentioned in my first comment, I tested your code and it works fine in my own project.

It is possible that somehow, the project generation went awry and continued to cause that problem.  There might be some files missing or corrupted when you created your project originally and that is why I kept asking if you have certain items relevant to a project that is missing.  You might have encountered a bug in your IDE before.  This problem happens from time to time based on my experience.
Random Solutions  
 
programming4us programming4us