VS2005 ASP.NET 2.0 does not fire event for dynamically created custom web controls

A

Amelyan

I *finally* narrowed down my problem to my custom web control. If I hookup
event inside dynamically created custom web control, it doesn't get fired.
However, event gets fired for any other standard dynamically created web
control. the code below works in VS 2003 (radio_CheckedChanged get
invoked), but it doesn't work in VS 2005.

Is there something extra I need to override or add in VS2005 to make event
fire?


namespace ClassLibrary1

{

[DefaultProperty("Text")]

[ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]

public class WebCustomControl1 : WebControl

{

[Bindable(true)]

[Category("Appearance")]

[DefaultValue("")]

[Localizable(true)]

public string Text

{

get

{

String s = (String)ViewState["Text"];

return ((s == null) ? String.Empty : s);

}

set

{

ViewState["Text"] = value;

}

}

protected override void RenderContents(HtmlTextWriter output)

{

base.RenderContents(output);

}

protected override void CreateChildControls()

{

Controls.Add(GetRadioButton());

}

public Control GetRadioButton()

{

TableCell cell = new TableCell();

RadioButton radio = new RadioButton();

radio.ID = "a_12311";

radio.CheckedChanged += new EventHandler(radio_CheckedChanged);

radio.Text = "Suka!!!!!";

radio.GroupName = "sadlfjklsakdjfas";

radio.Checked = false;

cell.Controls.Add(radio);

Table tbl = new Table();

tbl.Rows[tbl.Rows.Add(new TableRow())].Cells.Add(cell);

tbl.BorderWidth = 10;

return tbl;

}

void radio_CheckedChanged(object sender, EventArgs e)

{

throw new Exception("The method or operation is not implemented.");

}

}

}
 
T

tdavisjr

The looks like a composite control. However, you didn't implement the
Interface INamingContainer. This is required for all composite
controls or else events wont fire. Implement this interface and see
what happens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top