S
Shannon Cayze
Hello all,
I'm trying to develop a control that contains LinkButtons for which I
need to attach event handlers to the Click event. The following works
fine and the event handler is invoked:
public class TestCompositeControl : CompositeControl {
private LinkButton _linkButton = null;
protected override void CreateChildControls() {
base.CreateChildControls();
this._linkButton = new LinkButton();
this._linkButton.ID = "Link_Button";
this._linkButton.Text = "Link Button";
this._linkButton.Click += new EventHandler(_linkButton_Click);
this.Controls.Add(this._linkButton);
}
protected void _linkButton_Click(object sender, EventArgs e) {
}
}
However, the following will not allow the event handler to be invoked
when the LinkButton is placed in a Panel. When viewing the source,
it's apparent that no reference to __doPostBack is generated for the
LinkButton. I'm just not sure why.
public class TestCompositeControl : CompositeControl {
private LinkButton _linkButton = null;
private Panel _panel = new Panel();
protected override void CreateChildControls() {
base.CreateChildControls();
this._panel = new Panel();
this._panel.ID = "TestPanel";
this._linkButton = new LinkButton();
this._linkButton.ID = "Link_Button";
this._linkButton.Text = "Link Button";
this._linkButton.Click += new EventHandler(_linkButton_Click);
this._panel.Controls.Add(this._linkButton);
}
protected override void Render(HtmlTextWriter writer) {
this._panel.RenderControl(writer);
writer.WriteBreak();
base.Render(writer);
}
protected void _linkButton_Click(object sender, EventArgs e) {
}
}
I do have a specific reason for trying to do this. I'm implementing a
control that inherits from DataList and implements paging. I haven't
found a way to successfully add the paging LinkButtons directly to the
DataList's Controls collection, so I'm trying to add them to a panel
and render that panel, followed by the DataList itself.
Can anyone tell me how to do what I'm trying to do or suggest a better
way?
Thanks in advance,
Shannon
I'm trying to develop a control that contains LinkButtons for which I
need to attach event handlers to the Click event. The following works
fine and the event handler is invoked:
public class TestCompositeControl : CompositeControl {
private LinkButton _linkButton = null;
protected override void CreateChildControls() {
base.CreateChildControls();
this._linkButton = new LinkButton();
this._linkButton.ID = "Link_Button";
this._linkButton.Text = "Link Button";
this._linkButton.Click += new EventHandler(_linkButton_Click);
this.Controls.Add(this._linkButton);
}
protected void _linkButton_Click(object sender, EventArgs e) {
}
}
However, the following will not allow the event handler to be invoked
when the LinkButton is placed in a Panel. When viewing the source,
it's apparent that no reference to __doPostBack is generated for the
LinkButton. I'm just not sure why.
public class TestCompositeControl : CompositeControl {
private LinkButton _linkButton = null;
private Panel _panel = new Panel();
protected override void CreateChildControls() {
base.CreateChildControls();
this._panel = new Panel();
this._panel.ID = "TestPanel";
this._linkButton = new LinkButton();
this._linkButton.ID = "Link_Button";
this._linkButton.Text = "Link Button";
this._linkButton.Click += new EventHandler(_linkButton_Click);
this._panel.Controls.Add(this._linkButton);
}
protected override void Render(HtmlTextWriter writer) {
this._panel.RenderControl(writer);
writer.WriteBreak();
base.Render(writer);
}
protected void _linkButton_Click(object sender, EventArgs e) {
}
}
I do have a specific reason for trying to do this. I'm implementing a
control that inherits from DataList and implements paging. I haven't
found a way to successfully add the paging LinkButtons directly to the
DataList's Controls collection, so I'm trying to add them to a panel
and render that panel, followed by the DataList itself.
Can anyone tell me how to do what I'm trying to do or suggest a better
way?
Thanks in advance,
Shannon