Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Display list of links

Status
Not open for further replies.

rf222

Programmer
Jan 29, 2004
94
US
Should I use Link Control? It only has one link... I need to display several links... C# code please. Thanks
 
I would like to display URL links like this:



I know that Microsoft does not recomment to use Response.Write in .NET, so I would like to use custom control I guess. The problem is there is only one control: Hyper Link Control, but it does not display list like above. Also the list needs to be generated dynamicly based on web.config, so I do not know the number of links at design time....

There is another question related to this. How to inject custom HTML to the web form? Should I use placeholder control? Is this good idea to inject custom HTML anyway? Do I need to create custom control?

I am trying to understand what the best .NET 2 C# practise is in this case...

Thanks
 
For a dynamic list of links you can add them dynamically. There are many threds in this forum related to the topic. Basically something like:
Code:
        Dim hl As New HyperLink
        hl.ID = "the ID"
        hl.Text = "some test"
        hl.Target = "the target"
        hl.NavigateUrl = "the URL from web.config"
        Me.FindControl("Form1").Controls.Add(hl)
The code above simply adds the hyperlink to the page. You can add it to other controls like a table, placeholder etc. Also for layout you could use css.

As for the injecting of custom HTML, not sure what you mean by that.
 
Thanks, how would you insure that ID is unique? I will need to generate this in the loop. Is there a simple out-of-the-box way to generate unique ID for a dynamic control?

As far as inserting custom HTML, is there a control which allows you to enter custom HTML (generated by program dynamicly - unknown at design stage). Should I design my own custom control for this? What is the best practice?
 
Also another problem arose. Seems like after setting h1.NavigateURL .NET system reformats the URL. As a result the final output HTML is different and it does not work in my case.... Here is more details:

1) NEW CODE (I just wrote)

private void DisplayURL(string text, string url)
{
// Create a new hyperlink object.
HyperLink h1 = new HyperLink();
// Assign some text and an ID so you can retrieve it later.
h1.Text = text;
//h1.ID = "newButton"; This is created dynamicly
h1.NavigateUrl = url;

// Add the button to a PlaceHolder.
PlaceHolder1.Controls.Add(h1);
PlaceHolder1.Controls.Add(new LiteralControl("<br>"));
}

2) NEW OUTPUT HTML:

<a href="J:\+LIZ\Daily%20reports\20060413\RF_error.log">J:\+LIZ\Daily reports\20060413\RF_error.log</a>


3) OLD CODE:

Response.Write("<a href='" + path2 + "'>" + path2 + "</a> </br>");

4) OLD OUTPUT HTML:

<a href='J:\+LIZ\Daily reports\20060413\RF_error.log'>J:\+LIZ\Daily reports\20060413\RF_error.log</a>


IF you compare the putputs, you will see that the control reformats the URL string, since the output URL actually points to the file, it does not work... Can I force the control not to format the string??? What else can I do to fix this problem?



 
The new code (using control's property) replaces space with %20. This does now work when I click the file link....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top