I assume you have implemented your custom control with INamingContainer interface.
The event binding in ASP.net works on control IDs and INamingContainer will allow your custom control to follow the ClientID generation mechanism.
So if your custom control has proper ID all events within the control will be raised.
hope this will help.
Thanks,
Hemant
Edit:
protected void Page_Load(object sender, EventArgs e)
{
TemplateField tf = new TemplateField();
tf.ItemTemplate = new MyTemplateField();
GridView1.Columns.Add(tf);
GridView1.RowCommand += new GridViewCommandEventHandler(GridView1_RowCommand);
GridView1.DataSource = NewDataTable();
GridView1.DataBind();
}
template field
public class MyTemplateField : Control, ITemplate
{
Button btn;
public MyTemplateField()
{
btn = new Button();
btn.ID = "this button";
btn.Text = "Im the button";
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
CommandEventArgs cea = new CommandEventArgs("cmd",btn);
RaiseBubbleEvent(btn, cea);
}
public void InstantiateIn(Control container)
{
container.Controls.Add(btn);
}
}
you need to bubble the event.
Hope it will work. it worked at my end ;)
Thanks,
Hemant