Dynamically Created Controls in VS2005 ASP.NET 2.0

A

Amelyan

My standard dynamically created controls (e.g. Button, RadioButton, etc.)
stopped firing event assigned to them in VS2005 (final release) ASP.NET 2.0.
Is anyone else having the same problem?

I guess a better help would be for someone to recommend a proper way of
dynamically creating a control on the
page and having it fire event when form is submitted in ASP.NET 2.0. Maybe
a simple example.

Thanks,
 
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.");

}

}

}
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top