Why user control with code behind file doesn't want to compile under MVC2?

Posted by kyrisu on Stack Overflow See other posts from Stack Overflow or by kyrisu
Published on 2010-03-23T11:25:43Z Indexed on 2010/04/03 4:13 UTC
Read the original article Hit count: 445

Filed under:
|

I have user control in my MVC2 app placed in the Content folder (it's not supposed to be a view, just reusable part of the app).

UserControl1.ascx looks like:

<@ Control AutoEventWireup="true" Language="C#" CodeFile="~/Content/UserControl1.ascx.cs" Inherits="MVCDrill.Content.UserControl1" %>

<div runat="server" id="mydiv">
<asp:LinkButton id="lb_text" runat="server"></asp:LinkButton>
</div>

UserControl1.ascx.cs looks like:

using System;
using System.Web;
using System.Web.UI;

namespace MVCDrill.Content
{
    public class UserControl1 : UserControl
    {

        public string Text
        {
            get { return this.lb_text.Text; }
            set { this.lb_text.Text = value; }
        }
    }
}

I'm pretty sure this kind of stuff compiled under webforms but I'm getting compilation error:

'MVCDrill.Content.UserControl1' does not contain a definition for 'lb_text' and no extension method 'lb_text' accepting a first argument of type 'MVCDrill.Content.UserControl1' could be found (are you missing a using directive or an assembly reference?)

Am I missing something? How to change it (what is the alternative) in MVC2 ?

p.s. Intellisense sees lb_text with no problem. I've tried with different controls with the same outcome.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2