Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dynamically create new Hyperlinks in ASP.NET?

I'll explain what I'm trying to achieve:

I want to have a situation where I can create as many controls as I want by creating them in a loop in the code behind. I can do this while using PHP, by mixing the PHP code and the HTML code. This allows me to generate actual HTML tags dynamically.

In ASP.NET, I haven't found a way to replicate this functionality.

I've thought about using a loop in the code behind on something like the Init() function to create an array of new() objects, setting their attributes and hoping it is passed into the aspx file, but it didn't work.

How do I do this?

like image 850
chustar Avatar asked Nov 29 '22 20:11

chustar


1 Answers

If you want to creat Dynamically ASP.Net Hyperlink control You can simply do this:

HyperLink hyp = new HyperLink();
    hyp.ID = "hypABD";
    hyp.NavigateUrl = "";
    Page.Controls.Add(hyp);
like image 154
Muhammad Akhtar Avatar answered Dec 07 '22 22:12

Muhammad Akhtar