I now have a new problem with code behind files. None of the controls inside my aspx file are recognised inside the code behind file.
Code Behind
Code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Test1CodeBehind : System.Web.UI.Page
{
public void Click(object s, EventArgs e)
{
messageLabel.Text = "test comment";
}
}
Aspx file
Code:
<%@ Page Language="C#" CodeFile="test1.aspx.cs" Inherits="Test1CodeBehind" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
</head>
<body>
<form runat="server" id="form1">
<asp:Label id="messageLabel" runat="server" />
<asp:Button runat="server" OnClick="Click" Text="run code" />
</form>
</body>
</html>
My error is:
Code:
Error 2 The name 'messageLabel' does not exist in the current context C:\asp_sites\test2\App_Code\test1.aspx.cs 17 5 http://localhost:81/
Edited
As it turns out, my code behind file was inside the App_Code folder as suggested by Visual studio, this prevented it from running correctly. I spent hours trying to sort this out.