Trying to create Custom WebControl with Button click event method

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

  1. I can't seem to get my Custom WebControl to output a button whose click event
    is associated with a particular method.

    Here is the code I have right now that contains a panel and there is a
    button in that panel that should be associated with a event method - but it
    isn't working:
    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);
    }

    I should add that this Custom WebControl may eventually contain multiple
    Panels - is this the proper inheritance for this Custom WebControl:
    public class SurveyWebControl : System.Web.UI.WebControls.WebControl,
    System.Web.UI.INamingContainer

    Thanks,
    Novice
    =?Utf-8?B?Tm92aWNl?=, Sep 23, 2004
    #1
    1. Advertising

  2. Shouldn't you be doing it at the OnLoad() override? (checking for postback
    of course)..


    --
    Girish Bharadwaj
    http://msmvps.com/gbvb
    "Novice" <6tc1ATqlinkDOTqueensuDOTca> wrote in message
    news:...
    > I can't seem to get my Custom WebControl to output a button whose click

    event
    > is associated with a particular method.
    >
    > Here is the code I have right now that contains a panel and there is a
    > button in that panel that should be associated with a event method - but

    it
    > isn't working:
    > 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);
    > }
    >
    > I should add that this Custom WebControl may eventually contain multiple
    > Panels - is this the proper inheritance for this Custom WebControl:
    > public class SurveyWebControl : System.Web.UI.WebControls.WebControl,
    > System.Web.UI.INamingContainer
    >
    > Thanks,
    > Novice
    Girish Bharadwaj, Sep 23, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?Tm92aWNl?=

    Matt Berther Guest

    Hello Girish,

    Anywhere prior to/including OnPreRender should be fine... You're right, Render isnt the place for this...

    --
    Matt Berther
    http://www.mattberther.com

    > Shouldn't you be doing it at the OnLoad() override? (checking for
    > postback of course)..
    >
    Matt Berther, Sep 23, 2004
    #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. Purvi T
    Replies:
    0
    Views:
    831
    Purvi T
    Oct 19, 2004
  2. jorge
    Replies:
    2
    Views:
    1,263
    jorge
    May 26, 2004
  3. =?Utf-8?B?Tm92aWNl?=

    Event Handler for button click in Custom WebControl

    =?Utf-8?B?Tm92aWNl?=, Sep 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    510
    =?Utf-8?B?Tm92aWNl?=
    Sep 24, 2004
  4. Amy
    Replies:
    0
    Views:
    977
  5. Max2006
    Replies:
    2
    Views:
    1,565
    Walter Wang [MSFT]
    Sep 19, 2007
Loading...

Share This Page