B
Big Daddy
I created a composite control derived from UserControl. It has two
textboxes. The ascx file looks like this:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="RangeCriteriaControl.ascx.cs" Inherits="RangeCriteriaControl"
%>
<asp:TextBox ID="txtLow" runat="server" Columns="5"></asp:TextBox>
to
<asp:TextBox ID="txtHigh" runat="server" Columns="5"></asp:TextBox>
If I include this control in the aspx file of a page, it works great.
But I would like to be able to instantiate it programmatically. When I
try this from within the code-behind of my page:
_criteriaControl = new RangeCriteriaControl();
Controls.Add(_criteriaControl);
_criteriaControl.BindData();
Within the BindData() method, I try to fill in the two textboxes with
data, but the references to the two textbox controls are null. For
example, if this is the method:
public void BindData()
{
txtLow.Text = "2";
txtHigh.Text = "3";
}
txtLow and txtHigh are null. Why is this? Is there any way to create
my control programmatically and have the controls within it be
instantiated right away too?
Thanks in advance,
John
textboxes. The ascx file looks like this:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="RangeCriteriaControl.ascx.cs" Inherits="RangeCriteriaControl"
%>
<asp:TextBox ID="txtLow" runat="server" Columns="5"></asp:TextBox>
to
<asp:TextBox ID="txtHigh" runat="server" Columns="5"></asp:TextBox>
If I include this control in the aspx file of a page, it works great.
But I would like to be able to instantiate it programmatically. When I
try this from within the code-behind of my page:
_criteriaControl = new RangeCriteriaControl();
Controls.Add(_criteriaControl);
_criteriaControl.BindData();
Within the BindData() method, I try to fill in the two textboxes with
data, but the references to the two textbox controls are null. For
example, if this is the method:
public void BindData()
{
txtLow.Text = "2";
txtHigh.Text = "3";
}
txtLow and txtHigh are null. Why is this? Is there any way to create
my control programmatically and have the controls within it be
instantiated right away too?
Thanks in advance,
John