473,785 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1863
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*********@no spam.thanx> wrote in message
news:Ia******** ******@nospamth ankyou.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*********@no spam.thanx> wrote in message
news:Jv******** ******@nospamth ankyou.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\Framewor k\Sections\Cont rols\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*********@no spam.thanx> wrote in message
news:D$******** ******@nospamth ankyou.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*********@no spam.thanx> wrote in message
news:Jv******* *******@nospamt hankyou.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\Framewo rk\Sections\Con trols\BreadCrum b.cs.
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*********@no spam.thanx> wrote in message
news:n0******** ******@nospamth ankyou.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

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

Similar topics

2
1871
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 Studio reports that it cannot find server. What server is this? The start page works fine going to the internet and my normal Internet Explorer is working fine. VS 2003 v. 7.1.3044 Framework v. 1.1.4322 -- Thanks for any help, suggestions before...
5
3326
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 keywords, scan the web page and create links on any of those keywords... Is there any way to do this sort of thing? Thanks!
3
1612
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 traditional asp you could check the value as you looped through the recordset, but in asp.net I am not sure how to do it if you are binding to a control. Thanks, Chad
8
2257
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 to add comments at the bottom of each page, similar to the way the php, mysql, apache manuals work. PUNCHLINE_A:
1
5532
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 would be great , if i know how to create the dynamic HREF links like it should be getting different document based on each userid. Here is my part of jsp code for your reference: <%@ page...
3
2768
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 files are identified by an id in a database. How do I do this? I was thinking I could somehow make a list of <a href...> tags which could call a method in my c# code-behind. Is this possible? Or is there a better way?
9
2986
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 got the core of the javascript from here: http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm I noticed in the demo that sometimes the content takes a long
12
9508
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 trying to do is create a page that pulls up a list of items in a DB page, lists the items and creates a dynamic link using the item_id making the item_name a link to a more detailed page. So that when they click the Item_name it uses the item_id...
2
1458
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 on one page. For the database table, I've created the following columns: id, category, link_name, http, description My problem is that when I present the links, I want to group them by their category and have the category name as the section...
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.