Wednesday, September 28, 2011

Add Button & OnClick Event Handler Dynamically


        Button b = new Button();

        b.ID = "btnFire" + i;
        b.Text =  imagepath.Substring(imagepath.LastIndexOf("\\") + 1, imagepath.Length - imagepath.LastIndexOf("\\") - 1);
        b.ToolTip = imagepath.Substring(imagepath.LastIndexOf("\\") + 1, imagepath.Length - imagepath.LastIndexOf("\\") - 1);
        b.OnClientClick = "return alert('hi');";
        b.CommandArgument = b.ID; //passing this to event handler
       
        b.Command += new CommandEventHandler(LinkButton_Click); //handler
        form1.Controls.Add(b);

No comments:

Post a Comment