Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 27th, 2004, 12:42 AM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default response.write(hyperlink)

Hey everyone, ive been trying to figue out how to take a web address stored in an array and output it as a hyperlink on my page. I've searched the web forever and i finally came across this site. here is a sample of my code.

Dim outputlist(136) as string
outputlist(1) = "http://www.johnrules.com"

Response.Write("<a href = '" & outputlist(1) & "'>" & "</a>")

is this the best way to do this? If there is another way (table, database, whatever, I'm open to suggestions. The size of the array is going to vary based on user so the amount of hyperlinks being output has to be dynamic.
Thanks in advance for your help
--j


  #2 (permalink)  
Old April 27th, 2004, 07:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can create a hyperlink on the fly and pass in the URL for the NavigateURL property, then add it to the page. Response.Write() will work too; it's how things were done in the ASP world.
  #3 (permalink)  
Old April 27th, 2004, 02:50 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I'm sure I sound like an idiot, but how do you create a hyperlink on the fly? all of this code is going in the pageload section on my xxx.aspx.vb page, and it says that hyperlinks are not valid objects? and if response.write() works, do i have a syntactic error, because i have tried numereous ways but it only outputs a string or nothing at all. sorry for the dummy questions on my part.

  #4 (permalink)  
Old April 28th, 2004, 12:40 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi adolphus,

Are you still looking for a solution for this?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.


  #5 (permalink)  
Old April 28th, 2004, 07:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Dim objLink as New System.Web.UI.WebControls.HyperLink
objLink.ID = "some ID"

Page.Controls.Add(objLink)

Actually in the page you will probably want to have a container control such as a panel and add the control to that.

Panel.Controls.Add(objLink)

Help this helps,

Brian
  #6 (permalink)  
Old April 28th, 2004, 07:09 AM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually i figured it out last night.
dim outputlist(136)
outputlist(1) = "<a href = ""Http://www.disney.com"">Web Page Design</a>"
outputlist(2)...

instead of trying to store just the address, i stored the whole hyperlink code into the string array and wrote it out to the page with
for i=0 to 136
response.write(outputlist(i))

thanks for the help anyway :)

  #7 (permalink)  
Old April 28th, 2004, 07:41 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, that would work well. However, IMO, you're not really using .NET the way it's supposed to be used. Using Response.Write is "classic" ASP and will get you into troubles in .NET. This is because you cannot really control the location of the output of Response.Write. If you add code like that in Page_Load it will end up somewhere at the top of your page.

In .NET, it makes much more sense to use a databound control, like a DataList. You can bind this list to a datasource, like an array of HyperLink objects. The following example shows you what I mean:
Code:
<%@ Page Language="VB" %>
<script runat="server">
    Sub Page_Load(Sender As Object, E As EventArgs)

        Dim HyperLinks(1) As HyperLink

        HyperLinks(0) = New HyperLink
        HyperLinks(0).Text = "The Disney Site"
        HyperLinks(0).NavigateUrl = "http://www.disney.com"

        HyperLinks(1) = New HyperLink
        HyperLinks(1).Text = "Yahoo"
        HyperLinks(1).NavigateUrl = "http://www.yahoo.com"

        lstTest.DataSource = HyperLinks
        lstTest.DataBind()

    End Sub
</script>
<html>
<head>
</head>
<body>
    <asp:datalist id="lstTest" runat="server">
    <headertemplate>
        [list]
    </headertemplate>
    <itemtemplate>
        <li>
        <asp:hyperlink id="hyperTest" 
        navigateurl='<%# DataBinder.Eval(Container.DataItem, "NavigateUrl")%>' 
        runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Text")%>
        </asp:hyperlink>
        </li>
    </itemtemplate>
    <footertemplate>
        </ul>
    </footertemplate>
    </asp:datalist>
</body>
</html>
I prefer this kind of stuff over using Response.Write. This way of coding has a few benefits:

1. Clear separation of UI and code. You can change the layout of the page without affecting the code.
2. It's easy to modify the code; it's clean, simple and not mixed with markup
3. Additions are easily made. Want the Disney tag to open in a new Window? Just add this line:

        HyperLinks(0).Target = "_blank"

It may take some time to get used to this kind of programming syntax, and the databinding syntax may look difficult and odd at first, but I am sure in the end it will improve the quality of the applications you can write.

Just my 2 cents....

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Bombtrack by Rage Against The Machine (Track 1 from the album: Rage Against The Machine) What's This?
  #8 (permalink)  
Old September 11th, 2006, 03:05 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dim myHyperLinks As HyperLink

        myHyperLinks = New HyperLink
        myHyperLinks.Text = "The Asp.net Resource Site"
        myHyperLinks.NavigateUrl = "http://www.megasolutions.net"

form.controls.add(myhyperlinks)

hope it works.


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
response.write crmpicco Classic ASP Basics 1 January 27th, 2005 06:31 PM
response.write netcrawler Classic ASP Databases 4 September 29th, 2004 10:13 AM
Response.write Sach Classic ASP Components 5 March 19th, 2004 06:40 AM
Response.Write an SSI hcweb Classic ASP Basics 2 November 2nd, 2003 05:21 PM



All times are GMT -4. The time now is 04:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.