Results 1 to 2 of 2

Thread: dynamically creat linkbutton eventhandler

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    dynamically creat linkbutton eventhandler

    I created a dynamically link buttons, and want to pass the eventhandler to it, but it doesn't work. The function never gets called. My code is below:

    Code:
    LinkButton lbtnEdit = new LinkButton();
     protected void Button1_Click(object sender, EventArgs e)
            {
    foreach (Controls c in Controls)
    {
    if (c is textbox)
                        string sTextBoxID = ((TextBox)(c)).ID;
                        char cLast = sTextBoxID[sTextBoxID.Length - 1];
                        lbtnEdit.ID = "LinkButton" + cLast;
                        lbtnEdit.Click += new EventHandler(lbtnEdit_Click);
                        DIV.Controls.Add(lbtnEdit);
    
    }
    }
    
    }
            protected void lbtnEdit_Click(object sender, EventArgs e)
            {
                LinkButton lbtn = (LinkButton)sender;
                lbtn.ID.ToString();
                AddId.Visible = false ;
            }

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: dynamically creat linkbutton eventhandler

    Hey,

    I take it you don't get any errors when you try and compile the application?

    Have you tried stepping through the code to make sure everything is happening as you expect it to, i.e. does the Event Handler actually get assigned to the Button Click event?

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width