Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Big Daddy #1
Creating a custom user control programatically
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
Big Daddy Guest
-
Having trouble adding a web user control programatically.
Hi All; I am attempting to figure out how to add a user created control (test.ascx) to an ASP.NET page based on a user choice. I have created a... -
Programatically created controls in an ascx user control misbehaving
Hello I have a need to dynamically (programatically) create various different controls (TextBox, RadioButtonList, CheckBox, etc.) at page_load... -
Creating a custom control which contans user controls
I need to create a custom control which contains both default user controls and any other html or control the developer uses in between start and... -
Problem with web user control loaded programatically
I am loading web user controls into a web page programitically using the cone below: private void Page_Load(object sender, System.EventArgs e) ... -
Page Load fired 3 times Web user control is embedded in a custom control
Hi, I have built a custom control that build a table with 3 cells in it. The custom control is designed to add all child controls to cell#2,... -
Brennan Stehling #2
Re: Creating a custom user control programatically
You want to call the LoadControl method. It is explained here.
[url]http://msdn2.microsoft.com/en-us/library/c0az2h86.aspx[/url]
Brennan Stehling
[url]http://brennan.offwhite.net/blog/[/url]
Big Daddy wrote:> 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,
> JohnBrennan Stehling Guest
-
Big Daddy #3
Re: Creating a custom user control programatically
Thanks, that did the trick.
Big Daddy Guest



Reply With Quote

