Problem with Image button dynamic in radTreeView

2 posts, 0 answers
  1. Francisco
    Francisco avatar
    1 posts
    Member since:
    Jun 2012

    Posted 11 Jun 2012 Link to this post

    I have a problem.
    I need to create a dynamic image button and assign the event "click"  on a node of a "treeview", the problem is that when you click the image button disappears and never calls the event "lkbEliminar_Click".
        ImageButton lkbEliminar = new ImageButton();
          lkbEliminar.ImageUrl = "~/images/delete.png";
           lkbEliminar.ToolTip = "Eliminar Documento";
            lkbEliminar.Click += new System.Web.UI.ImageClickEventHandler(lkbEliminar_Click);  
          nodoHijoMenor.Controls.Add(lkbEliminar);
             nodoHijoMayor.Nodes.Add(nodoHijoMenor);
     
      protected void lkbEliminar_Click(object sender, ImageClickEventArgs e)
            {
                string x = "asdas";
                x = x + "asdsa";
     
               }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Jun 2012 Link to this post

    Hi Francisco,

    One suggestion is you can add a node template with an image button dynamically as follows.

    C#:
    public partial class treeview_dynamicImageButton : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            nodoHijoMayor.NodeTemplate = new TextBoxTemplate();
            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadTreeNode nodoHijoMenor = new RadTreeNode();
                nodoHijoMayor.Nodes.Add(nodoHijoMenor);
            }
            nodoHijoMayor.DataBind();
        }
    }
    class TextBoxTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            ImageButton lkbEliminar = new ImageButton();
            lkbEliminar.ImageUrl = "~/images/bullet5.jpg";
            lkbEliminar.Click += new ImageClickEventHandler(lkbEliminar_Click);
            container.Controls.Add(lkbEliminar);
        }
     
        void lkbEliminar_Click(object sender, ImageClickEventArgs e)
        {
            string x = "asdas";
            x = x + "asdsa";
        }
    }

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top