Reputation: 9850
I declared a hyperlink in asp.net as follows;
<asp:HyperLink ID="hyp" runat="server" Text="new user"></asp:HyperLink>
but, I am not getting the underline link, where I could click on it and go to a new page.
HyperLink hyp = new HyperLink();
hyp.ID = "hyp";
hyp.NavigateUrl = "http://localhost/";
hyp.Visible = true;
Page.Controls.Add(hyp);
Upvotes: 0
Views: 3813
Reputation: 3272
You are defining the link multiple times.
The first time is in your ASPX
-page. This time only the ID
- and Text
-property are set.
The second time you create a new link, and this time you do not set the Text
-property (which is mandatory), by using:
HyperLink hyp = new HyperLink();
hyp.ID = "hyp";
and
Page.Controls.Add(hyp);
Your code-behind should just contain:
hyp.NavigateUrl = "http://localhost/";
This part is optional, but based on your example does not seem necessary:
hyp.Visible = true;
Upvotes: 2
Reputation: 7747
According to MSDN you should also set the Text
property. Maybe the way you are declaring it in both the webpage and the code behind is confusing things.
Upvotes: 2