locked
Custom Events inside Custom Controls RRS feed

  • Question

  • Hi All,
     I am new to custom controls, i am trying to create custom event in custom control.
     I have done that but that event is not getting triggered in my aspx page.
     Here below code i have did.
     

    [ToolboxData("<{0}:GridViewExtension runat=server></{0}:GridViewExtension>")]
        public class GridViewExtension : GridView,IPostBackEventHandler
    
    public event EventHandler ExcelDownloadClick;
            private LinkButton excelDownload = new LinkButton();
    
    protected override void CreateChildControls()
            {
                //if (_showExcelDownload)
                //{
                    excelDownload.Text = "ExcelDownload";
                    excelDownload.Font.Bold = true;
                    excelDownload.ForeColor = _foreColor;
                    excelDownload.BackColor = _backColor;
                    excelDownload.Click += ExcelDownloadClick;
                    //this.HeaderRow.Cells[0].Controls.Add(excelDownload);
                    this.Controls.Add(excelDownload);
                //}
                base.CreateChildControls();
            }
    
    protected void excelDownload_Click(object sender,EventArgs e)
            {
                this.DataBind();
                if (ExcelDownloadClick != null)
                    ExcelDownloadClick(sender, e);
            }
    
            #region IPostBackEventHandler Members
    
            void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
            {
                ExcelDownloadClick(this, new EventArgs());
            }
    
            #endregion
    
    In aspx page i am calling like this
    grdMaster.ExcelDownloadClick += new EventHandler(grdMaster_ExcelDownloadClick);
    Please help me out where i am going wrong

    THanks in advance
    PradeepKumar
    Thursday, August 13, 2009 10:16 AM

Answers

  • Instead of the line

    excelDownload.Click += ExcelDownloadClick;

    you probably wanted to do

    excelDownload.Click += excelDownload_Click;
    • Proposed as answer by Rudedog2Moderator Thursday, August 13, 2009 7:05 PM
    • Marked as answer by Harry Zhu Thursday, August 20, 2009 5:41 AM
    Thursday, August 13, 2009 12:19 PM

All replies

  • Hi,
    For web application releated you need to go for www.asp.net
    i hope it will help you
    Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
    Thursday, August 13, 2009 12:02 PM
  • Instead of the line

    excelDownload.Click += ExcelDownloadClick;

    you probably wanted to do

    excelDownload.Click += excelDownload_Click;
    • Proposed as answer by Rudedog2Moderator Thursday, August 13, 2009 7:05 PM
    • Marked as answer by Harry Zhu Thursday, August 20, 2009 5:41 AM
    Thursday, August 13, 2009 12:19 PM
  • The first hint should have been that it did not compile.
    Mark the best replies as answers. "Fooling computers since 1971."
    Thursday, August 13, 2009 7:05 PM
    Moderator