How to create dynamic linkbutton in asp.net

{0 Comments}

To create dynamic link button then use the following code which will remain same to make any control in asp.net. I have tested on many of them. And lastly don’t forget to add the same to the form of the asp.net page otherwise it will through an error. Then code for that is as follows.

 C# |  copy code |? 
1
 protected void Page_Load(object sender, EventArgs e)
2
    {
3
        //here we are creating on page load event so link will appear as the page is loaded
4
        LinkButton LnkBtn = new LinkButton();
5
        LnkBtn.ID = "LinkButton1"; //assigning a ID;
6
        LnkBtn.Text = "LinkButton";//adding default text
7
        form1.Controls.Add(LnkBtn);//add the LinkButton to the form
8
    }

Above code will exactly create the same link button which you will get on drag and drop of the link button from the tool panel.

Leave a Comment

Your email address will not be published.