Composite Control not receiving DataGrid (child control) events?

Discussion in 'ASP .Net Building Controls' started by debartsa, Apr 19, 2004.

  1. debartsa

    debartsa Guest

    Hi Everybody,


    I have a composite control (CompositeControl) which uses an instance of the
    DataGrid (DataCtrl1) as a child control.
    The DataGrid is dynamically created in the CreateChildControls() method of
    my control and is responsible for rendering a list of web sites. The
    DataGrid also generates an "Edit" push button alongside each of the list of
    names (which will eventually be used for editing the list of items).

    Everything works fine! the DataGrid does the work of rendering the list of
    names and the "Edit" button as expected. My stumbling block occurs the
    "Edit" button is clicked, for some reason the EditCommand event of the
    DataGrid isn't firing? Does it have something to do with the .aspx page
    consuming the control and the fact that the button click occurs during
    postback?

    My code ...

    // CompositeControl.cs
    //
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Collections;
    using System.Diagnostics;

    namespace AMT.Portal.Controls {

    /// <summary>
    /// My Compoiste control which dynamically creates a DataGrid
    (DataCtrl1)
    /// </summary>

    public class CompositeControl : WebControl, INamingContainer
    {

    protected System.Web.UI.WebControls.DataGrid DataCtrl1;
    protected System.Collections.Hashtable myTeamLinks;

    protected override void CreateChildControls() {

    Controls.Clear();
    DataCtrl1 = new DataGrid();
    DataCtrl1.AutoGenerateColumns = false;

    BoundColumn col = new BoundColumn();
    col.HeaderText = "Key";
    col.DataField = "Key";

    DataCtrl1.Columns.Add(col);

    EditCommandColumn EditCol = new EditCommandColumn();
    EditCol.EditText = "Edit";
    EditCol.UpdateText = "Update";
    EditCol.CancelText = "Cancel";
    EditCol.ButtonType = ButtonColumnType.PushButton;

    DataCtrl1.Columns.Add(EditCol);

    DataCtrl1.DataSource = GetLinks();
    DataCtrl1.DataBind();
    Controls.Add(DataCtrl1);

    this.DataCtrl1.EditCommand += new
    DataGridCommandEventHandler(this.myDataGrid_EditCommand);

    }

    /// <summary>
    /// Returns an IEnumerable type for the DataGrid to Bind
    /// </summary>

    private Hashtable GetLinks() {
    myTeamLinks = new Hashtable();
    myTeamLinks.Add("Microsoft Site", "http://www.microsoft.com");
    myTeamLinks.Add("IBM Site", "http://www.ibm.com");
    myTeamLinks.Add("Compaq", "http://www.hp.com");
    myTeamLinks.Add("Google Site", "http://www.google.com");

    return myTeamLinks;
    }


    /// <summary>
    /// The Event Handler that isn't being called when the Edit button
    of the DataGrid (Child Control) is clicked ?
    /// </summary>

    protected void myDataGrid_EditCommand(object sender,
    DataGridCommandEventArgs e)
    {
    Trace.Write("The Data Grid EditCommand Event was fired");
    }


    Thanks for any help!
    Sam
    debartsa, Apr 19, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,092
    David Schwartz
    Dec 9, 2003
  2. debartsa
    Replies:
    1
    Views:
    248
    John Saunders
    Apr 23, 2004
  3. Chris Simmons

    Composite Control - Event not firing in child control

    Chris Simmons, Oct 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    356
    Chris Simmons
    Oct 28, 2004
  4. Chad
    Replies:
    0
    Views:
    214
  5. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    306
    David Boike
    Aug 7, 2003
Loading...

Share This Page