Event Handler for button click in Custom WebControl

Discussion in 'ASP .Net' started by =?Utf-8?B?Tm92aWNl?=, Sep 24, 2004.

  1. Hey all, I've already posted this question and two posters offered
    suggestions and they worked - but now I would like to know why - and if
    possible the answer to a second question.

    Here is my problem:
    I am trying to write a custom WebControl - at some point this WebControl
    will output a bunch of controls into several Panel objects. But I just
    recently got my WebControl to output a single button and attach an event
    handler to that button (thanks to those two posters).

    Here is the code I previously had:
    protected override void Render(HtmlTextWriter output)
    {
    Panel panel = new Panel();
    nextButton = new Button();
    nextButton.Text = "Submit";
    nextButton.Click += new EventHandler(nextButtonClick);
    nextButton.Visible = true;
    panel.Controls.Add(nextButton);
    Controls.Add(panel);
    panel.RenderControl(output);
    }

    So it was then suggested that I move this code into the OnLoad - which I did
    (except for the "panel.RenderControl(output);" line) and it worked.

    The signature for my class is:
    public class ReportWebControl : System.Web.UI.WebControls.WebControl,
    System.Web.UI.INamingContainer

    So my first and most important question:
    1. How should I be creating and outputting multiple controls (buttons, text
    fields, etc) onto a web page from within a webcontrol (exp - should I make
    all of the controls that I will output a member variable of my class, should
    I put all of the creation of those controls in the OnLoad method and then
    output all the panels in the Render method)?

    2. Why does the event handler get "lost" when I put the event handler
    association within the Render method?

    Thanks,
    Novice
    =?Utf-8?B?Tm92aWNl?=, Sep 24, 2004
    #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. Purvi T
    Replies:
    0
    Views:
    813
    Purvi T
    Oct 19, 2004
  2. =?Utf-8?B?RGl2eWE=?=

    Button in custom webcontrol - event handler not called

    =?Utf-8?B?RGl2eWE=?=, Apr 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,588
    Victor Garcia Aprea [MVP]
    May 1, 2004
  3. =?Utf-8?B?Tm92aWNl?=
    Replies:
    2
    Views:
    4,084
    Matt Berther
    Sep 23, 2004
  4. Divya

    Button in custom webcontrol - event handler not working

    Divya, Apr 30, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    164
    Victor Garcia Aprea [MVP]
    May 1, 2004
  5. Divya
    Replies:
    2
    Views:
    172
    Victor Garcia Aprea [MVP]
    May 1, 2004
Loading...

Share This Page