views:

55

answers:

2

This one should be pretty simple. I am making a non-MVC ASP.NET 2.0 site. VS2008 seems to generate controls with a <script> area -- I want the code in a codebehind, so I've manually hooked that up.

I have the following:

widget.ascx:

<%@ Control Language="C#" ClassName="widget" Codebehind="widget.ascx.cs" Inherits="widget"%>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

widget.ascx.cs:

namespace webapp
{
  public partial class widget : System.Web.UI.Control
  {
    protected void Page_Load(object sender)
    {
        Label1.Text = Session["user_id"].ToString();
    }
  }
}

I copy and pasted this stuff from ASPX pages that use codebehind files, but when I try to compile I get errors that Label1 does not exist in this context.

All help in the matter appreciated.

A: 

does that match the declaration of your other pages / controls?

try using codebeside instead of codebehind / better to look it at declarations in other project files.

eglasius
Yes, that matches the other declarations. I've tried several other permutations and they haven't worked either. :( I've tried codebeside too to no luck.
cookiecaper
A: 

Well, I must have created the control the wrong way. I started over with a fresh template and it all worked as expected. If you are experiencing this problem, just copy your code out and try to ask Visual Studio to generate the files from the user control templates again. Make sure you right-click on project name and add a new file.

cookiecaper

related questions