I have a simple asp.net user control:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="QueryDefinitionItem.ascx.cs"
Inherits="xxx.UserControls.QueryDefinitionItem" %>
<link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
<div class="title">
<h1 id="TextField" runat="server"></h1>
</div>
Code behind:
public partial class QueryDefinitionItem : System.Web.UI.UserControl
{
private string m_text;
protected void Page_Load(object sender, EventArgs e)
{
TextField.InnerText = m_text;
}
public void SetText(string text)
{
m_text = text;
}
}
I use LoadControl to load one instance programatically:
protected void Page_Load(object sender, EventArgs e)
{
var control = (QueryDefinitionItem)LoadControl(typeof (QueryDefinitionItem),null);
control.SetText("test2");
itemsPanel.Controls.Add(control);}
I then use the SetText function to set the text and once the Page Load is fired I get a NullReferenceException that says TextField is null...
I cant figure out why.