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

Discussion in 'ASP .Net' started by Amelyan, Nov 4, 2005.

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

  2. Amelyan

    tdavisjr Guest

    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.
     
    tdavisjr, Nov 4, 2005
    #2
    1. Advertising

  3. Amelyan

    Amelyan Guest

    Your suggestion worked. Thank you.


    "tdavisjr" <> wrote in message
    news:...
    > 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.
    >
     
    Amelyan, Nov 5, 2005
    #3
    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. skedward
    Replies:
    0
    Views:
    1,525
    skedward
    May 29, 2006
  2. Amelyan

    Dynamically Created Controls in VS2005 ASP.NET 2.0

    Amelyan, Nov 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    136
    Amelyan
    Nov 4, 2005
  3. Amelyan
    Replies:
    0
    Views:
    205
    Amelyan
    Nov 4, 2005
  4. Richard Huang
    Replies:
    1
    Views:
    143
  5. Biguana
    Replies:
    3
    Views:
    506
Loading...

Share This Page