How can I use a Button object in my custom control and be able to handle the
click event? I feel like I must be missing something obvious here. I can
render a button directly in HTML, and I can capture that click event, but I
need to embed WebControl objects and handle events from them. The code I'm
using is below. Only Render and CreateChildControls are called, I have
breakpoints on all other methods that are never hit.
Thanks,
Erick
public class ButtonTest : System.Web.UI.WebControls.WebControl,
IPostBackDataHandler, IPostBackEventHandler
{
Button button;
protected override void Render(HtmlTextWriter output)
{
button.RenderControl(output);
}
public bool LoadPostData(String postDataKey, NameValueCollection
values) {
return false;
}
public void RaisePostDataChangedEvent() {
}
private void ButtonClick(object sender, EventArgs e) {
}
protected override void CreateChildControls() {
button = new Button();
button.ID = "Submitter";
button.Text = "Submit";
button.Click += new EventHandler(this.ButtonClick);
this.Controls.Add(button);
}
public void RaisePostBackEvent(string eventArgument) {
}
}
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.