Custom Web Control - viewstate and event wiring questions

Discussion in 'ASP .Net' started by =?Utf-8?B?amVzc2UgamFtZXMgMjAyMA==?=, Aug 18, 2006.

  1. I cannot get viewstate nor can I wire up events to child controls... Any
    thoughts are appreciated. Example code is below:

    public class SelectCashFlowPeriods:Table
    {
    const int DROPDOWNWIDTH = 106;

    protected DropDownList Period1;
    protected Button SubmitSelection;

    public SelectCashFlowPeriods()
    {
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
    EnsureChildControls();

    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    Period1.RenderControl(writer);
    writer.RenderEndTag(); // end td
    writer.RenderEndTag(); // end tr

    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    SubmitSelection.RenderControl(writer);
    writer.RenderEndTag(); // end td
    writer.RenderEndTag(); // end tr
    }

    protected override void CreateChildControls()
    {
    Controls.Clear();

    Period1 = new DropDownList();

    SubmitSelection = new Button();
    SubmitSelection.Text = "submit me";

    Period1.AutoPostBack = true;
    Period1.EnableViewState = true;
    Period1.SelectedIndexChanged +=new
    EventHandler(Period_SelectedIndexChanged);
    Period1.Width = Unit.Pixel(DROPDOWNWIDTH);

    Period1.Items.Add(new ListItem("select one", "0"));
    Period1.Items.Add(new ListItem("one", "1"));
    Period1.Items.Add(new ListItem("two", "2"));
    Period1.Items.Add(new ListItem("three", "3"));

    base.CreateChildControls();
    }

    protected virtual void Period_SelectedIndexChanged(object sender,
    EventArgs e)
    {
    // do stuff
    }
    }
     
    =?Utf-8?B?amVzc2UgamFtZXMgMjAyMA==?=, Aug 18, 2006
    #1
    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. Oisin Grehan
    Replies:
    3
    Views:
    494
    Natty Gur
    Jul 15, 2003
  2. =?Utf-8?B?SG9tYW0=?=

    Dynamic controls and event wiring

    =?Utf-8?B?SG9tYW0=?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    372
    =?Utf-8?B?SG9tYW0=?=
    Feb 16, 2005
  3. Jordan
    Replies:
    4
    Views:
    628
    Bruce Barker
    Sep 1, 2005
  4. Sosh
    Replies:
    5
    Views:
    4,133
    =?Utf-8?B?V296emE=?=
    Nov 16, 2005
  5. Andrew Robinson

    Dynamically Loaded User Control Event Wiring

    Andrew Robinson, May 23, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    804
    Steven Cheng[MSFT]
    May 28, 2007
Loading...

Share This Page