T
Tom K
Hi folks,
I am trying to inherit from the DataGrid control and add a
few buttons and dropdowns to a
a header I am rendering above the grid. This all looks
fine (the controls render correctly) however I am not able
to capture the events from these child controls. I am
overriding
the OnBubbleEvent method which correctly captures events
from within the underlying datagrid itself but fails to
capture events from the child buttons and dropdowns. I
have tried to register delagates at various stages of the
control lifecycle however this seems to make
no difference.
I have included a simplified version of the Grid Control
below.
Any help would be greatly appreciated.
Thanks
Tom
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace SimpleGridCtl
{
public class SimpleDataGrid :
System.Web.UI.WebControls.DataGrid , INamingContainer
{
System.Web.UI.WebControls.Button m_btnTest;
protected override void CreateChildControls()
{
Controls.Clear();
m_btnTest = new Button();
m_btnTest.Click += new EventHandler(m_btnTest_Click);
m_btnTest.CommandName = "Test";
m_btnTest.EnableViewState=true;
Controls.Add(m_btnTest);
base.CreateChildControls();
}
private void m_btnTest_Click(object sender, EventArgs e)
{
// never gets hit
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
protected override void OnItemCommand
(DataGridCommandEventArgs e)
{
base.OnItemCommand (e);
}
protected override bool OnBubbleEvent(object source,
EventArgs e)
{
// never gets hit for a the child button
return false;
}
protected override void Render(HtmlTextWriter writer)
{
m_btnTest.RenderControl(writer);
writer.Write("<BR>");
base.Render (writer);
}
}
}
I am trying to inherit from the DataGrid control and add a
few buttons and dropdowns to a
a header I am rendering above the grid. This all looks
fine (the controls render correctly) however I am not able
to capture the events from these child controls. I am
overriding
the OnBubbleEvent method which correctly captures events
from within the underlying datagrid itself but fails to
capture events from the child buttons and dropdowns. I
have tried to register delagates at various stages of the
control lifecycle however this seems to make
no difference.
I have included a simplified version of the Grid Control
below.
Any help would be greatly appreciated.
Thanks
Tom
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace SimpleGridCtl
{
public class SimpleDataGrid :
System.Web.UI.WebControls.DataGrid , INamingContainer
{
System.Web.UI.WebControls.Button m_btnTest;
protected override void CreateChildControls()
{
Controls.Clear();
m_btnTest = new Button();
m_btnTest.Click += new EventHandler(m_btnTest_Click);
m_btnTest.CommandName = "Test";
m_btnTest.EnableViewState=true;
Controls.Add(m_btnTest);
base.CreateChildControls();
}
private void m_btnTest_Click(object sender, EventArgs e)
{
// never gets hit
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
protected override void OnItemCommand
(DataGridCommandEventArgs e)
{
base.OnItemCommand (e);
}
protected override bool OnBubbleEvent(object source,
EventArgs e)
{
// never gets hit for a the child button
return false;
}
protected override void Render(HtmlTextWriter writer)
{
m_btnTest.RenderControl(writer);
writer.Write("<BR>");
base.Render (writer);
}
}
}