Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 684827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:51:37+00:00 2026-05-14T01:51:37+00:00

I have user control in my MVC2 app placed in the Content folder (it’s

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:51:37+00:00Added an answer on May 14, 2026 at 1:51 am

    The “correct” way to implement this type of functionality is to use a partial view in the Shared view folder — with no codebehind — and supply the data with a view model.

    Ex:

    <%@ Page Language="C#"
        Inherits="System.Web.Mvc.ViewUserControl<LinkButtonModel>" %>
    
    <div id="mydiv">
        <a href="#" id="lb_text"><%= Model.LinkButtonText %></a>
    </div>
    
    <script type="text/javascript">
        $(function() {
             $('#lb_text').click( function() {
                 $(this).closest('form').submit();
             });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MVC2 I have used Page.User.Identity.Name using the <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl %> How
I have a MVC2 user control that I want to dynamically load the menu
i have user control, which i render on several views. i want to show
I have an User Control that host another controls like panel, chart controls. Right
I have a user control bound to appropriate ViewModel. I have a GraphLayout (using
I have this User Control XAML: <Window x:Class=MyProj.Dialog xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:shell=http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell mc:Ignorable=d>
I have a user control that is being integrated to the page on run
I have a user control with a div like this: <div runat=server id=pnlShippingMethods class=checkoutstep>
I have a user control with several buttons, which need to take different actions
I have a user control called DashboardUserControl.ascx It has a function: public void setPagination(Boolean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.