locked
Problem with event not raised on a LinkButton in a Custom Control RRS feed

  • Question

  • User-593237760 posted

    Hi everybody, i want you to help me to resolve this problem of event, i tested a lot of things and i've started to abandon...

     

    So, this is the context : I created a Control inherited from Table and, in this control i've a control named ColumnTable (inherited from TableCell). This last control will serve to make sorting operations on my Table (which is filled with a list pre-binded).

    This ColumnTable control contains a LinkButton. With a click on this LinkButton, i want to raise an event that will call an other event.

     

    I tried to do that:

     

     /// <summary>
            /// Name of the column
            /// </summary>
            public string Name { get; set; }
    
    /// <summary>
            /// Init of the control
            /// </summary>
            /// <param name="e"></param>
            protected override void OnInit(EventArgs e)
            {
    
               
    
                this.ID = string.Format("Column{0}",this.Name.Trim().Replace(" ",""));
    
                this.linkButton.ID = string.Format("LinkButton{0}", this.Name.Trim().Replace(" ", ""));
                this.linkButton.Text = this.Name;
    
                this.linkButton.Text = this.Name;
                this.Controls.Add(this.linkButton);
    
                
    
                this.linkButton.CssClass = "label";
     
                
    
                base.OnInit(e);
    
                this.EnsureChildControls();
    
                this.linkButton.Click += new EventHandler(linkButton_Click);
            }
    
    void linkButton_Click(object sender, EventArgs e)
            {
    
    //Event created
                this.OnHyperLinkClick(e);
            }

     


    And also that :

     

    /// <summary>
            /// Creation of the control
            /// </summary>
            /// <returns></returns>
            protected Panel CreateControl()
            {
                Panel panel = new Panel();
    
                
    
                this.linkButton.Text = this.Name;
                panel.Controls.Add(this.linkButton);
    
                this.linkButton.CssClass = "label";
    
                return panel;
            }
    
            /// <summary>
            /// Control Panel added to ColumnTable
    /// </summary>
    protected override void CreateChildControls() { this.Controls.Add(this.CreateControl()); base.CreateChildControls(); } /// <summary> /// Init of the control /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { this.ID = string.Format("Column{0}",this.Name.Trim().Replace(" ","")); this.linkButton.ID = string.Format("LinkButton{0}", this.Name.Trim().Replace(" ", "")); base.OnInit(e); this.EnsureChildControls(); this.linkButton.Click += new EventHandler(linkButton_Click); } void linkButton_Click(object sender, EventArgs e) {
                            //Event created 
                this.OnHyperLinkClick(e);
            }

      

    I never pass through the event Click of my LinkButton, i don't understand why... My controls are added, it's like if it doesn't recognize the LinkButton .

     

    If you have answers, i'll be happy, thanks :) .

     

     

     

    Thursday, August 7, 2008 6:05 AM

Answers

  • User-593237760 posted
    I found the reason of the problem, it's because i had a bad organization in my pages, i did all on the prerender, therefore i have to do that in the load. It works.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 8, 2008 5:15 AM