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
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
Ascx file, all suggested solutions below works
Codebehind of ascx
Thanks for the inspiration!