C
Chris Simmons
Hello:
I am experiencing an issue where I have a composite control
(TestOuter) composed of more composite (TestInner) controls. When I
am seeing is if the TestInner control is placed on a webform, the
events of the control fire. If TestInner controls are placed within
the TestOuter control, these events never fire.
Here's some sample code:
// BEGIN CODE
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace MyControls
{
/// <summary>
/// Inner collection of RadioButtons
/// </summary>
public class TestInner : WebControl, INamingContainer
{
public TestInner() : base( HtmlTextWriterTag.Div )
{
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
RadioButton firstRadioButton, secondRadioButton;
Label output;
protected override void CreateChildControls()
{
firstRadioButton = new RadioButton();
firstRadioButton.ID = UniqueID + "_first";
firstRadioButton.Text = "First";
firstRadioButton.GroupName = UniqueID;
firstRadioButton.CheckedChanged +=
new EventHandler(firstRadioButton_CheckedChanged);
firstRadioButton.AutoPostBack = true;
Controls.Add( firstRadioButton );
secondRadioButton = new RadioButton();
secondRadioButton.ID = UniqueID + "_second";
secondRadioButton.Text = "Second";
secondRadioButton.GroupName = UniqueID;
secondRadioButton.CheckedChanged +=
new EventHandler(secondRadioButton_CheckedChanged);
secondRadioButton.AutoPostBack = true;
Controls.Add( secondRadioButton );
output = new Label();
Controls.Add( output );
}
private void firstRadioButton_CheckedChanged(object sender,
EventArgs e)
{
output.Text = "First chosen!";
}
private void secondRadioButton_CheckedChanged(object sender,
EventArgs e)
{
output.Text = "Second chosen!";
}
}
}
// END CODE
When added to a webform, ViewState is maintained (the radio buttons
remain where they were clicked) between postbacks. Now, if I create a
control which is composed of two of these controls, the events
(first_CheckedChanged or second_CheckedChanged) for the respective
TestInner controls do not fire.
Here is the sample code for TestOuter:
// BEGIN CODE
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Com.Fpl.Pgen.RiskManagement.Web.Controls
{
/// <summary>
/// Inner collection of RadioButtons
/// </summary>
public class TestOuter : WebControl, INamingContainer
{
public TestOuter() : base( HtmlTextWriterTag.Div )
{
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
TestInner firstTestInner, secondTestInner;
protected override void CreateChildControls()
{
firstTestInner =
new TestInner();
Controls.Add( first );
secondTestInner =
new TestInner();
Controls.Add( second );
}
}
}
// END CODE
Would someone be so kind as to show me where I'm fouling up? How can
I make the TestInner's (first and second) events fire when encased in
another control?
I am experiencing an issue where I have a composite control
(TestOuter) composed of more composite (TestInner) controls. When I
am seeing is if the TestInner control is placed on a webform, the
events of the control fire. If TestInner controls are placed within
the TestOuter control, these events never fire.
Here's some sample code:
// BEGIN CODE
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace MyControls
{
/// <summary>
/// Inner collection of RadioButtons
/// </summary>
public class TestInner : WebControl, INamingContainer
{
public TestInner() : base( HtmlTextWriterTag.Div )
{
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
RadioButton firstRadioButton, secondRadioButton;
Label output;
protected override void CreateChildControls()
{
firstRadioButton = new RadioButton();
firstRadioButton.ID = UniqueID + "_first";
firstRadioButton.Text = "First";
firstRadioButton.GroupName = UniqueID;
firstRadioButton.CheckedChanged +=
new EventHandler(firstRadioButton_CheckedChanged);
firstRadioButton.AutoPostBack = true;
Controls.Add( firstRadioButton );
secondRadioButton = new RadioButton();
secondRadioButton.ID = UniqueID + "_second";
secondRadioButton.Text = "Second";
secondRadioButton.GroupName = UniqueID;
secondRadioButton.CheckedChanged +=
new EventHandler(secondRadioButton_CheckedChanged);
secondRadioButton.AutoPostBack = true;
Controls.Add( secondRadioButton );
output = new Label();
Controls.Add( output );
}
private void firstRadioButton_CheckedChanged(object sender,
EventArgs e)
{
output.Text = "First chosen!";
}
private void secondRadioButton_CheckedChanged(object sender,
EventArgs e)
{
output.Text = "Second chosen!";
}
}
}
// END CODE
When added to a webform, ViewState is maintained (the radio buttons
remain where they were clicked) between postbacks. Now, if I create a
control which is composed of two of these controls, the events
(first_CheckedChanged or second_CheckedChanged) for the respective
TestInner controls do not fire.
Here is the sample code for TestOuter:
// BEGIN CODE
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Com.Fpl.Pgen.RiskManagement.Web.Controls
{
/// <summary>
/// Inner collection of RadioButtons
/// </summary>
public class TestOuter : WebControl, INamingContainer
{
public TestOuter() : base( HtmlTextWriterTag.Div )
{
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
TestInner firstTestInner, secondTestInner;
protected override void CreateChildControls()
{
firstTestInner =
new TestInner();
Controls.Add( first );
secondTestInner =
new TestInner();
Controls.Add( second );
}
}
}
// END CODE
Would someone be so kind as to show me where I'm fouling up? How can
I make the TestInner's (first and second) events fire when encased in
another control?