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 7065763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:59:45+00:00 2026-05-28T04:59:45+00:00

I got a web user control where I have controls that needs to be

  • 0

I got a web user control where I have controls that needs to be fed with some data from variables or properties from the underlying page.

<%@ Control Language="C#" AutoEventWireup="False" CodeFile="Header.ascx.cs" Inherits="Site.UserControls.Base.Header" %>
<asp:Literal runat="server" Text='<%# Testing %>' id="ltrTesting" />

Codebehind

namespace Site.UserControls.Base
{
    public partial class Header : UserControlBase
    {
        public string Testing = "hello world!";

        protected void Page_Load(object sender, EventArgs e)
        {
            //this.DataBind(); // Does not work
            //PageBase.DataBind(); // Does not work
            //base.DataBind(); // Does not work
            //Page.DataBind(); // Does not work
        }
    }
}

I did read this topic, but it wont solve my problem, I assume it’s because this is a user control and not a page. I want to get property value from code behind

  • 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-28T04:59:45+00:00Added an answer on May 28, 2026 at 4:59 am

    Solved this, solution below

    Since I used a web user control in this case the usual scenarios would not work. But by putting a databind in the page that controls the user control, or any materpage in the chain above the web user control the code started to work

    MasterPage codebehind

    public partial class MasterPages_MyTopMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Databind this to ensure user controls will behave
            this.DataBind();
        }
    }
    

    Ascx file, all suggested solutions below works

    <%@ Control Language="C#" AutoEventWireup="False" CodeFile="Header.ascx.cs" Inherits="Site.UserControls.Base.Header" %>
    1: <asp:Literal runat="server" Text='<%# DataBinder.GetPropertyValue(this, "Testing") %>' />
    2: <asp:Literal runat="server" Text='<%# DataBinder.Eval(this, "Testing") %>' />
    3: <asp:Literal runat="server" Text='<%# Testing2 %>' />
    

    Codebehind of ascx

    namespace Site.UserControls.Base
    {
        public partial class Header : UserControlBase //UserControl
        {
            public string Testing { get { return "hello world!"; } }
            public string Testing2 = "hello world!";
    
            protected void Page_Load(object sender, EventArgs e)
            { }
        }
    }
    

    Thanks for the inspiration!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a web browser control that needs to have a specific height set.
I've got a web application that I'm trying to optimize. Some of the controls
I got a backend web service containing massive amounts of data that I have
I have an ASP.Net web user control that contains a TextBox and a calendar
I have inherited a working VB.NET 2.0 web app that has several User Controls
I have got myself really tied up with a web user control and the
I have some HTML that I got from a designer, from witch I made
I've got a web app that sends out emails in response to a user-initaited
I've got a little c# windows service that periodically pulls xml from a web
I've got a user control which contains a number of other user controls. I

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.