如何在ASP.NET中执行这些动态链接? [英] How do I do these dynamic links in ASP.NET ?

查看:67
本文介绍了如何在ASP.NET中执行这些动态链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我是经典ASP,我曾经有一种标准方式制作顶级

网站导航链接。我有一个包含文件,其中包括一个像

这个... ...

Sub MakeLink(TocURL,TocText)

如果TocURL = ThisURL然后

Response.Write("< br>"& TocText)

Else

Response.Write(" ;< br>< a href ="""& TocURL&""">"& TocText&"< / a>")

结束如果

结束子


(航空代码,所以忽略拼写错误),其中ThisURL已被设置为
的URL
当前页面。然后,我可以做类似的事情......


MakeLink" /" ;,&\"Home

MakeLink" /contact.asp"," ;联系我们


等等。这个包含文件可以为每个

页面创建一组链接。


现在,我如何在ASP.NET中实现相同的目标?我想我可以在我想要链接的地方有一个

标签,然后在

Page_Load事件中有一个sub来构建一个包含HTML的字符串。在

结束时,label.Text可以设置为字符串。


考虑到ASP.NET的方式,这看起来有点不雅观设置为

允许结构化编码。有没有人对此有更好的建议?


TIA


-

Alan Silver

(此行下面添加的任何内容都与我无关)

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)

推荐答案

Alan:

社区入门套件有一个设置良好的breadcrump组件(但它是数据库驱动的
)。你可能想看看它。


我一直看到它设置的方式是通过一个用户控件,你在每个上面包含

你的页面。然后,用户控件将被提供给XML文件

或数据库,在那里它将使用当前页面来确定要构建的
breadcrumb。这比MakeLinkxxx,yyy

解决方案更优雅,因为它使用户控制完全自给自足,因为它可以轻松修改通过一个XML文件(因为不得不对每个页面上的链接进行硬编码)。


您还可以获得免费控制来为您执行此操作:
http://www.loudcarrot.com/webcontrols/navpath .aspx


通常只需将数据读入某种类型的集合(比如

arraylist)并将其绑定到数据网格...


Karl

-

我的ASP.Net教程
http://www.openmymind.net/

" Alan Silver" <人********* @ nospam.thanx>在消息中写道

新闻:Ia ************** @ 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.

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...
你好,
<我经典的ASP,我曾经有一种标准的方式来制作顶级的网站导航链接。我有一个包含文件,其中包括一个像
这个......

Sub MakeLink(TocURL,TocText)
如果TocURL = ThisURL那么
Response.Write( < br>"& TocText)
其他
Response.Write(< br>< a href ="""& TocURL&"" ;">"& TocText&"< / a>")
结束如果
结束子

(航空代码,所以忽略拼写错误) ,其中ThisURL已设置为当前页面的URL。然后我可以做类似的事情......

MakeLink" /"," Home"
MakeLink" /contact.asp" ;,联系我们

等等。然后,这个包含文件可以为每个
页面创建一组链接。

现在,我如何在ASP.NET中实现相同的目标?我想我可以在我想要链接的地方有一个
标签,然后在
Page_Load事件中有一个sub来构建一个包含HTML的字符串。在sub /的末尾,label.Text可以设置为字符串。

考虑到ASP.NET设置为
允许的方式,这看起来有点不雅观结构化编码。有没有人对此有更好的建议?

TIA

-
Alan Silver
(此行下面添加的任何内容都与我无关)
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)



> Alan:
社区入门套件有一个设置良好的breadcrump组件(但它是
数据库驱动)。你可能想看一下。


谢谢,我已经拿到了套件,但还没有取得任何进展

呢。起初这是非常令人生畏的,因为我仍然在整个ASP.NET的想法中找到了我的脚,我决定暂时离开它。


我会去看看我是否能找到这个组件。希望它应该有所帮助

我了。

我一直看到它设置的方式是通过一个用户控件,你包括
在你的每个上面页。然后,用户控件将从XML文件或数据库中获取,在该文件中,它将使用当前页面来确定要构建的面包屑。这比MakeLinkxxx,yyy
解决方案更优雅,因为它使用户控制完全自给自足,因为它可以通过XML文件轻松修改(如同反对必须
硬编码每页上的链接)


这是一个非常好的主意。将包含文件(就像在经典ASP中)链接在

中我没有问题,但我可以看到使用XML在

中的优势文件。自我生成的网站指南立即春天来到

介意...

您还可以获得免费控制来为您执行此操作:
http://www.loudcarrot.com/webcontrols/navpath.aspx

谢谢,但我想尽可能多地掌握它。

我想获得使用MS控件的经验,看看有多少我可以做b
$ b。你不是真的和其他人一样学习。

通常只需将数据读入某种类型的集合(比如说是一个arraylist)和绑定就可以了。那个数据网格...
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...




感谢您的回复。


自我发布以来,另一个让我印象深刻的点。用于

的包含文件包括标题的一部分以及内容的最高位。这是

方便,因为我可以为作者等提供META标签,以及包含文件中所有CSS文件的

链接。这样所有页面都使用了

一个来源,使其易于更改。如果我在ASP.NET中使用自定义控件来执行此操作,我是否仍然可以包含部分< head>?如果我理解对,
理解正确,控件必须是网页形式,并且只有当你进入< body>时,你才可以打开其中一个。如果是这样,你如何得到

< head> ;?的公共部分?我是否回去旧的包含文件,或者

有更好的方法吗?


再次感谢


-

Alan Silver

(此行下面添加的任何内容都与我无关)



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)


>社区入门套件有一个设置良好的breadcrump组件(但是
>The community starter kit has a well-setup breadcrump component (but
它是由数据库驱动的)。你可能想看一下。
it''s database driven). You might want to check it out.




卡尔,


刚刚找到这个,我不能找到它。说实话,我有点迷失了。

。请问你能告诉我我在找什么吗?


谢谢


-

Alan Silver

(此行下面添加的任何内容都与我无关)



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)


这篇关于如何在ASP.NET中执行这些动态链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆