473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I do these dynamic links in ASP.NET ?

Hello,

I Classic ASP, I used to have a standard way of making the top-level
site navigation links. I had an include file which included a Sub like
this ...

Sub MakeLink(TocURL, TocText)
If TocURL = ThisURL Then
Response.Write("<br>" & TocText)
Else
Response.Write("<br><a href=""" & TocURL & """>" & TocText & "</a>")
End If
End Sub

(air code, so ignore typos), where ThisURL had been set to the URL of
the current page. I could then do something like ...

MakeLink "/", "Home"
MakeLink "/contact.asp", "Contact Us"

and so on. This include file could then create a set of links for every
page.

Now, how do I achieve the same end in ASP.NET? I guess I could have a
label in the place where I want the links to be, then have a sub in the
Page_Load event that builds a string containing the HTML. At the end of
the sub, the label.Text could be set to the string.

This seems a little inelegant considering the way ASP.NET is set up to
allow structured coding. Does anyone have a better suggestion for this?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
12 1832
Alan:
The community starter kit has a well-setup breadcrump component (but it's
database driven). You might want to check it out.

The way I've always seen it set up is via a user control which you include
atop each of your page. The user control would then be fed off an XML file
or Database where it would use the current page to figure out what
breadcrumb to build. This is more elegant than the MakeLink "xxx", "yyy"
solution because it makes the user control totally self-sufficient as well
as making it easily modifiable via an XML file (as oppsed to having to
hard-code the links on each page)

You can also get free controls to do this for you:
http://www.loudcarrot.com/webcontrols/navpath.aspx

Normally it's done simply by reading data into some type of collection (say
an arraylist) and binding that to a datagrid...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:Ia**************@nospamthankyou.spam...
Hello,

I Classic ASP, I used to have a standard way of making the top-level
site navigation links. I had an include file which included a Sub like
this ...

Sub MakeLink(TocURL, TocText)
If TocURL = ThisURL Then
Response.Write("<br>" & TocText)
Else
Response.Write("<br><a href=""" & TocURL & """>" & TocText & "</a>")
End If
End Sub

(air code, so ignore typos), where ThisURL had been set to the URL of
the current page. I could then do something like ...

MakeLink "/", "Home"
MakeLink "/contact.asp", "Contact Us"

and so on. This include file could then create a set of links for every
page.

Now, how do I achieve the same end in ASP.NET? I guess I could have a
label in the place where I want the links to be, then have a sub in the
Page_Load event that builds a string containing the HTML. At the end of
the sub, the label.Text could be set to the string.

This seems a little inelegant considering the way ASP.NET is set up to
allow structured coding. Does anyone have a better suggestion for this?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #2
>Alan:
The community starter kit has a well-setup breadcrump component (but it's
database driven). You might want to check it out.
Thanks, I've already got the kit, but haven't made any headway into it
yet. It's very daunting at first, and as I'm still finding my feet with
the whole ASP.NET idea, I decided to leave it for the moment.

I'll go and see if I can find this component. Hopefully it should help
me out.
The way I've always seen it set up is via a user control which you include
atop each of your page. The user control would then be fed off an XML file
or Database where it would use the current page to figure out what
breadcrumb to build. This is more elegant than the MakeLink "xxx", "yyy"
solution because it makes the user control totally self-sufficient as well
as making it easily modifiable via an XML file (as oppsed to having to
hard-code the links on each page)
That's a very good idea. I don't have a problem with having the links in
the include file (as it was in Classic ASP), but I can see advantages in
using an XML file. Self-generating site guides immediately spring to
mind ...
You can also get free controls to do this for you:
http://www.loudcarrot.com/webcontrols/navpath.aspx
Thanks, but I'd like to get to grips with as much of it myself as I can.
I'd like to get experience using just the MS controls and see how much I
can do. You don't really learn as much with other people's.
Normally it's done simply by reading data into some type of collection (say
an arraylist) and binding that to a datagrid...


Thanks for the reply.

One other point that struck me since I posted. The include files used to
include part of the header as well as the top bit of content. This was
convenient as I could have the META tags for author, etc, as well as the
link to the CSS file all in the include file. That way all pages used
the one source, making it easy to change. If I use a custom control to
do this in ASP.NET, can I still include parts of the <head>? If I
understand right, controls have to be in a web form, and you can only
open one of those once you are inside the <body>. If so, how do you get
common parts for the <head>? Do I go back the old include files, or is
there a better way?

Thanks again

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #3
>The community starter kit has a well-setup breadcrump component (but
it's database driven). You might want to check it out.


Karl,

Just been looking for this, and I can't find it. I'm a bit lost in there
to be honest. Please could you tell me what I'm looking for?

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #4
See:

http://www.codeproject.com/aspnet/Lo...readcrumbs.asp

http://www.codeproject.com/aspnet/breadcrumbs.asp

http://www.search-this.com/website_d...mbs_Print.aspx

for sample code.

Breadcrumb navigation allows you to display the current page's
context within the site structure. The benefit of a breadcrumb is
that it makes obvious the ways in which the pages have been
grouped and allows the user both to navigate between these
pages and understand the site arrangement structure.


Juan T. Llibre
ASP.NET MVP
===========
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:Jv**************@nospamthankyou.spam...
The community starter kit has a well-setup breadcrump component (but it's
database driven). You might want to check it out.


Karl,

Just been looking for this, and I can't find it. I'm a bit lost in there
to be honest. Please could you tell me what I'm looking for?

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #5
Phil,
Wow, looks like the community portal has really changed since last I looked
at it. I don't remember it being a server control, but you can find their
breadcrumb in
Engine\Framework\Sections\Controls\BreadCrumb.cs.

The problem is that unless you are familiar with how the sections work,
you'll be a little loss.

The free control that I pointed you to has free source code, so again, you
might wannat ake a look at it.

As for your question about the <head></head>...it isn't true that
server/user controls must be placed inside <form></form> Some controls,
namely those which participate in viewstates must. So if your user/server
control has a textbox, linkbutton, button, ... then yes it must be in a
<form></form>...if you are only rendering HTML such as <head>, <title> and
<meta> you should be ok

Cheers,
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:D$**************@nospamthankyou.spam...
Alan:
The community starter kit has a well-setup breadcrump component (but it's
database driven). You might want to check it out.


Thanks, I've already got the kit, but haven't made any headway into it
yet. It's very daunting at first, and as I'm still finding my feet with
the whole ASP.NET idea, I decided to leave it for the moment.

I'll go and see if I can find this component. Hopefully it should help
me out.
The way I've always seen it set up is via a user control which you includeatop each of your page. The user control would then be fed off an XML fileor Database where it would use the current page to figure out what
breadcrumb to build. This is more elegant than the MakeLink "xxx", "yyy"
solution because it makes the user control totally self-sufficient as wellas making it easily modifiable via an XML file (as oppsed to having to
hard-code the links on each page)


That's a very good idea. I don't have a problem with having the links in
the include file (as it was in Classic ASP), but I can see advantages in
using an XML file. Self-generating site guides immediately spring to
mind ...
You can also get free controls to do this for you:
http://www.loudcarrot.com/webcontrols/navpath.aspx


Thanks, but I'd like to get to grips with as much of it myself as I can.
I'd like to get experience using just the MS controls and see how much I
can do. You don't really learn as much with other people's.
Normally it's done simply by reading data into some type of collection (sayan arraylist) and binding that to a datagrid...


Thanks for the reply.

One other point that struck me since I posted. The include files used to
include part of the header as well as the top bit of content. This was
convenient as I could have the META tags for author, etc, as well as the
link to the CSS file all in the include file. That way all pages used
the one source, making it easy to change. If I use a custom control to
do this in ASP.NET, can I still include parts of the <head>? If I
understand right, controls have to be in a web form, and you can only
open one of those once you are inside the <body>. If so, how do you get
common parts for the <head>? Do I go back the old include files, or is
there a better way?

Thanks again

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #6
Juan,

Thanks for those, there's plenty to keep me quiet for a while!!
See:

http://www.codeproject.com/aspnet/Lo...readcrumbs.asp

http://www.codeproject.com/aspnet/breadcrumbs.asp

http://www.search-this.com/website_d...mbs_Print.aspx

for sample code.

Breadcrumb navigation allows you to display the current page's
context within the site structure. The benefit of a breadcrumb is
that it makes obvious the ways in which the pages have been
grouped and allows the user both to navigate between these
pages and understand the site arrangement structure.


Juan T. Llibre
ASP.NET MVP
===========
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:Jv**************@nospamthankyou.spam...
>The community starter kit has a well-setup breadcrump component (but it's
>database driven). You might want to check it out.


Karl,

Just been looking for this, and I can't find it. I'm a bit lost in there
to be honest. Please could you tell me what I'm looking for?

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #7
>Phil,
Wow, looks like the community portal has really changed since last I looked
at it. I don't remember it being a server control, but you can find their
breadcrumb in
Engine\Framework\Sections\Controls\BreadCrumb.c s.
Thanks, now I know where to look ;-)
The problem is that unless you are familiar with how the sections work,
you'll be a little loss.
A "little"? Try a lot!! There are so many files there, it's hard to know
where to start.
The free control that I pointed you to has free source code, so again, you
might wannat ake a look at it.
Thanks, I did take a look. I didn't realise at first that they included
source code. That changes things as I can now learn from them.
As for your question about the <head></head>...it isn't true that
server/user controls must be placed inside <form></form> Some controls,
namely those which participate in viewstates must. So if your user/server
control has a textbox, linkbutton, button, ... then yes it must be in a
<form></form>...if you are only rendering HTML such as <head>, <title> and
<meta> you should be ok


I realised this last night when I remembered using a Literal control to
set the <title> of a page. It occurred to me that this wasn't in a form.

OK, so let me phrase the question slightly differently then. In Classic
ASP, I used to create an include file that had part of the <head>
(common bits like some META tags, the link to the stylesheet and so on),
the closing </head> tag, the opening <body> tag, and the parts of the
HTML that were common to all pages (which usually included the
navigational links).

In ASP.NET, I think this might be a problem. My current understanding is
that the best way to do the common code part is to put it in a custom
control, and use that control on the page. The problem would be that the
main page would not have the </head> and <body> tags in it. Wouldn't the
ASP.NET engine take an exception (no pun intended) to that? From what I
have seen (haven't got it clear enough yet), it likes to generate some
of these bits itself. Am I wrong here? Please clarify.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #8
>The way I've always seen it set up is via a user control which you
include atop each of your page. The user control would then be fed off
an XML file or Database where it would use the current page to figure
out what breadcrumb to build.


It occurred to me last night, won't this mean that *every* single page
request will involve a file read or database query? If so, won't that
have a serious performance impact? I know my original suggestion of
having the links inside the custom control doesn't have the flexibility
of the XML file, but it would be very fast.

Any comments?

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #9
You could place the DataSet in Cache. If you are pulling from an xml file,
you could place a File Dependency to the xml file driving your cached
DataSet.

If it is coming from the a database, you could still cache it. 2.0 will
have a database cache feature built in, but there are some samples out there
for database cache dependency in 1.1

I couldn't find the link I used to write mine, but here are some MSDN links:

http://msdn.microsoft.com/msdnmag/is...04/WickedCode/

http://msdn.microsoft.com/msdnmag/is...e/default.aspx

bill

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:n0**************@nospamthankyou.spam...
The way I've always seen it set up is via a user control which you
include atop each of your page. The user control would then be fed off
an XML file or Database where it would use the current page to figure
out what breadcrumb to build.


It occurred to me last night, won't this mean that *every* single page
request will involve a file read or database query? If so, won't that
have a serious performance impact? I know my original suggestion of
having the links inside the custom control doesn't have the flexibility
of the XML file, but it would be very fast.

Any comments?

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #10
Alan:
ASP.Net probably won't care, but VS.Net might not like it very much. An
alternative you might not have considered is to use master pages for the
common functionality:

http://www.metabuilders.com/Tools/MasterPages.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:tk**************@nospamthankyou.spam...
Phil,
Wow, looks like the community portal has really changed since last I lookedat it. I don't remember it being a server control, but you can find theirbreadcrumb in
Engine\Framework\Sections\Controls\BreadCrumb.c s.


Thanks, now I know where to look ;-)
The problem is that unless you are familiar with how the sections work,
you'll be a little loss.


A "little"? Try a lot!! There are so many files there, it's hard to know
where to start.
The free control that I pointed you to has free source code, so again, youmight wannat ake a look at it.


Thanks, I did take a look. I didn't realise at first that they included
source code. That changes things as I can now learn from them.
As for your question about the <head></head>...it isn't true that
server/user controls must be placed inside <form></form> Some controls,
namely those which participate in viewstates must. So if your user/server
control has a textbox, linkbutton, button, ... then yes it must be in a
<form></form>...if you are only rendering HTML such as <head>, <title> and<meta> you should be ok


I realised this last night when I remembered using a Literal control to
set the <title> of a page. It occurred to me that this wasn't in a form.

OK, so let me phrase the question slightly differently then. In Classic
ASP, I used to create an include file that had part of the <head>
(common bits like some META tags, the link to the stylesheet and so on),
the closing </head> tag, the opening <body> tag, and the parts of the
HTML that were common to all pages (which usually included the
navigational links).

In ASP.NET, I think this might be a problem. My current understanding is
that the best way to do the common code part is to put it in a custom
control, and use that control on the page. The problem would be that the
main page would not have the </head> and <body> tags in it. Wouldn't the
ASP.NET engine take an exception (no pun intended) to that? From what I
have seen (haven't got it clear enough yet), it likes to generate some
of these bits itself. Am I wrong here? Please clarify.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #11
>You could place the DataSet in Cache. If you are pulling from an xml file,
you could place a File Dependency to the xml file driving your cached
DataSet.
That's clever. Caching is a new one on me (as is everything at the
moment!!). I had a brief look at the pages below, and the second one
seems to have what I need, although I think it will need some careful
reading before I feel confident enough to use it.

However, it does mean that I can get on with looking at using an XML
file for the data and not worrying about killing the server. When I've
got the basic functionality working, I can then look at caching the data
to improve performance.

Thanks for the info and links.
If it is coming from the a database, you could still cache it. 2.0 will
have a database cache feature built in, but there are some samples out there
for database cache dependency in 1.1

I couldn't find the link I used to write mine, but here are some MSDN links:

http://msdn.microsoft.com/msdnmag/is...04/WickedCode/

http://msdn.microsoft.com/msdnmag/is...e/default.aspx

bill

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:n0**************@nospamthankyou.spam...
>The way I've always seen it set up is via a user control which you
>include atop each of your page. The user control would then be fed off
>an XML file or Database where it would use the current page to figure
>out what breadcrumb to build.


It occurred to me last night, won't this mean that *every* single page
request will involve a file read or database query? If so, won't that
have a serious performance impact? I know my original suggestion of
having the links inside the custom control doesn't have the flexibility
of the XML file, but it would be very fast.

Any comments?

--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #12
>Alan:
ASP.Net probably won't care, but VS.Net might not like it very much. An
alternative you might not have considered is to use master pages for the
common functionality:

http://www.metabuilders.com/Tools/MasterPages.aspx


Karl,

Thanks for the link. I think I'm suffering from information overload at
the moment!! I had a look at that page, but I think it needs printing
out and reading carefully.

I'm going to have a go at the XML file approach first as that looks very
promising. I might come back to the master pages stuff later.

Thanx again

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Glenn | last post by:
Dynamic help topic links show properly and search brings up links, but when any link is clicked I receive a "Page Cannot be displayed message in the Explorer window and the title bar of Visual...
5
by: Sally B. | last post by:
Hello, I searched, but couldn't find answers--probably because I'm not sure what this is called... Anyway, I have about 50 web pages and I want to have some JavaScript that will read in a list of...
3
by: Chad THomas | last post by:
I have a data repeater controll on a page. in each row that is displayed, I would like to have an action column that has differnet links shown depending on certain criteria from the database. In...
8
by: Sandy Pittendrigh | last post by:
I have a how-to-do-it manual like site, related to fishing. I want to add a new interactive question/comment feature to each instructional page on the site. I want (registered) users to be able...
1
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It...
3
by: Peter K | last post by:
Hi I need to make a list of "download file links" on a webpage. All the data is dynamic - it depends on the user's actions how many files, and which files, I need to present in the list. The...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
12
by: Lazoris | last post by:
OK heres a newb question and I'm sorry for it, but im getting back into web design after like 5 years off and im stuck even though i should know the problem i cant seem to correct it atm. What I'm...
2
by: ibec | last post by:
Hi I'm new to the forum and MySQL and PHP. I hope you'll excuse the simple question. Here's my problem: On our website I'm trying to put together a dynamic collection of links that will be presented...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.