Dynamically Created Controls in VS2005 ASP.NET 2.0

Discussion in 'ASP .Net Web Controls' started by Amelyan, Nov 3, 2005.

  1. Amelyan

    Amelyan Guest

    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,
    Amelyan, Nov 3, 2005
    #1
    1. Advertising

  2. Amelyan

    Amelyan Guest

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

    }

    }

    }

    "Amelyan" <bamelyan at wi.rr.com> wrote in message
    news:...
    > 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,
    >
    >
    Amelyan, Nov 4, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amelyan
    Replies:
    2
    Views:
    674
    Amelyan
    Nov 5, 2005
  2. Replies:
    3
    Views:
    671
    jim4u
    Apr 10, 2006
  3. Bob Rock
    Replies:
    1
    Views:
    611
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
  4. msimmons
    Replies:
    0
    Views:
    452
    msimmons
    Jul 16, 2009
  5. Richard Huang
    Replies:
    1
    Views:
    120
Loading...

Share This Page