By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

Trying to create Custom WebControl with Button click event method

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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:24**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
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)..


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.