Trying to create Custom WebControl with Button click event method

G

Guest

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
 
G

Girish Bharadwaj

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

Matt Berther

Hello Girish,

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top