如何在ASP.NET页面上使用框架?

时间:2022-07-07 15:17:59

How do you correct use frame on a asp.net page, so I have a left frame and a right frame, when I click the links on the page presented in the left frame, it loads the according page in the right frame? On top of this, I need to have a master page on all the right frame's pages.

你如何在asp.net页面上更正使用框架,所以我有一个左框架和一个右框架,当我点击左框架中显示的页面上的链接时,它会在右框架中加载相应的页面?除此之外,我需要在所有正确的框架页面上都有一个母版页。

How do I do this? or is there another way to achieve the same effect?

我该怎么做呢?还是有另一种方法可以达到同样的效果?

Thanks, Ray.

4 个解决方案

#1


5  

Yup. Frames are evil. You shouldn't really use them.

对。框架是邪恶的。你不应该真的使用它们。

They cause problems, but in a (very)few edge cases they can be useful and cheaper in terms of development time, they still show up in generated api documentation quite a lot.

它们会导致问题,但在(很少)边缘情况下它们在开发时间方面可能有用且成本更低,它们仍然在生成的api文档中出现了很多。

But anyway, seeing as how you asked how to use them, here we go

但无论如何,看看你如何使用它们,我们走了

First up, it depends on whether you want to use a frameset, or just put some iframes into a page, iframes maybe easier, but will describe a frameset. Some references below. If you dig around the wayback machine on archive.org, you will get to see some examples, also Sun's online java docs used to be in framesets, but have not looked at them for years.

首先,这取决于你是想使用框架集,还是只是将一些iframe放入页面,iframe可能更容易,但会描述一个框架集。以下一些参考文献如果你在archive.org上挖掘回路机器,你会看到一些例子,Sun的在线java文档曾经是在框架集中,但多年来都没有看过它们。

http://www.w3schools.com/tags/tag_frameset.asp
http://www.w3schools.com/tags/tag_iframe.asp

Basically, the contents of each frame are individual pages, and the frames themselves must be named, within the file which contains the frameset, which might look a little like this:

基本上,每个帧的内容都是单独的页面,并且框架本身必须在包含框架集的文件中命名,这可能看起来像这样:

<html>
<frameset cols="25%,75%">
  <frame name="_left" src="nav.aspx" />
  <frame name="_right" src="foo.aspx" />
</frameset>
</html>

So, for the sake of the excercise, give the left frame attribute name="__left" and name="__right" for the right.

因此,为了练习,请为右侧提供左框架属性name =“__ left”和name =“__ right”。

Important bits about links
Any links inside your right frame that need to target that frame should have target= "_self", and any that need to escape the frame and set the location of the parent page, should have target="_top".

关于链接的重要部分右框内需要定位该框架的任何链接都应该有target =“_ self”,任何需要转义框架并设置父页面位置的链接都应该有target =“_ top”。

The links in your left frame will need to have the attribute target="_right", and that should load the appropriate document into the right frame when the link is clicked.

左侧框架中的链接需要具有属性target =“_ right”,并且应该在单击链接时将相应的文档加载到右侧框架中。

The rest of it is pretty much normal, treat the contents of your right hand frame as a normal page, make a master page as normal, all the normal html, head, body tags etc. There is nothing really different about frames in aspnet or php or anything else, its just html.

其余部分非常正常,将右侧框架的内容视为普通页面,使主页面正常,所有正常的html,头部,正文标签等.aspnet中的框架没有什么不同PHP或其他任何东西,它只是HTML。

There you have it, there may be a few things I have missed, because they're not something I use very often these days, but sometimes, when accessibility and all that don't matter, they can be a quick and dirty fix. e.g some obscure admin page on a web service site, that will get visited 12 times a year by a geek who understands what is going on.

你有它,可能有一些我错过的东西,因为它们不是我现在经常使用的东西,但有时,当可访问性和所有无关紧要时,它们可以是一个快速和肮脏的修复。例如,一个网站服务网站上的一些模糊的管理页面,每年会被一个了解正在发生的事情的极客访问12次。

So, they are evil, but that shouldn't stop you learning about them, you will get to really understand why they are evil, and form your own opinion as to when and when not to use them.

所以,它们是邪恶的,但这不应该阻止你了解它们,你将真正理解为什么它们是邪恶的,并形成你自己的意见,何时何时不使用它们。

#2


3  

Frames are generally frowned upon in modern web development for a few reasons (I won't get into them here). You're better off using CSS to make a 2 column layout. There are a lot of good tutorials on how to make layouts like this all over the web. One example can be found here:

在现代Web开发中,框架通常是不受欢迎的,原因有几个(我不会在这里介绍它们)。你最好使用CSS来制作2列布局。关于如何在整个网络上制作这样的布局,有很多很好的教程。可以在这里找到一个例子:

http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/

The example on that site looks like this:

该网站上的示例如下所示:

http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/finished.html

If you want the layout to fit on the screen, just define a height for #main. You just need to add this to your CSS after you're finished:

如果您希望布局适合屏幕,只需为#main定义高度。您只需在完成后将其添加到CSS中:

#main{height:600px}

Change the "600px" to whatever height you want if it doesn't fit for you.

如果它不适合您,请将“600px”更改为您想要的任何高度。

To use it on a master page, just make your master page follow the example above, and then make the inside of the #main <div /> tag your primary ContentPlaceholder

要在母版页上使用它,只需使您的母版页按照上面的示例操作,然后将#main

标记的内部作为主要ContentPlaceholder

#3


0  

The short and sweet answer?

短而甜蜜的回答?

Frames and framesets are no longer necessary or useful in web development, and they create many more problems than they solve.

框架和框架集在Web开发中不再是必需或有用的,它们会产生比它们解决的问题更多的问题。

In more detail:

更详细:

There's three things that you're probably using frames to help with:

有三件事你可能正在使用框架来帮助:

1) You want to have a navigation bar on the left, and have a separate content area on the right, basically vertical separation.

1)你想在左边有一个导航栏,右边有一个单独的内容区域,基本上是垂直分隔。

Non-frame solution:

Use regular HTML and CSS to create a 2 column layout. See some of the other resources or "The Last Guide to CSS Layout You'll Ever Need".

使用常规HTML和CSS创建2列布局。查看其他一些资源或“您需要的CSS布局最后指南”。

2) You want to be able to have one file with the navigation that you don't have to have a version of it on several different pages.

2)您希望能够拥有一个带有导航的文件,您不必在几个不同的页面上拥有它的版本。

Non-frame solution:

Keep the navigation in a seperate file, and just include it in all of your content pages. In ASP.NET, you can create a UserControl, or .ascx file and include it in all of your changes. Put your navigation in the UserControl and you only need to change it in one place.

将导航保存在单独的文件中,并将其包含在所有内容页面中。在ASP.NET中,您可以创建UserControl或.ascx文件,并将其包含在所有更改中。将导航放在UserControl中,您只需在一个位置更改它。

3) You want the quicker performance of only the content frame needing to reload, and not the navigation frame.

3)您希望仅更快地执行需要重新加载的内容框架,而不是导航框架。

Non-frame solution:

The extra time to load the whole page is negligible, and the simplicity of serving a single document at a time more than makes up for the tiny performance hit.

加载整个页面的额外时间可以忽略不计,并且一次提供单个文档的简单性足以弥补微小的性能损失。

#4


0  

you can put the iframe code on the body section. an example given below. try this :)

你可以把iframe代码放在body部分。下面给出一个例子。试试这个 :)

<iframe width="100%" height="600px" scrolling="no" seamless="yes" src="https://facebook.com"></iframe>

#1


5  

Yup. Frames are evil. You shouldn't really use them.

对。框架是邪恶的。你不应该真的使用它们。

They cause problems, but in a (very)few edge cases they can be useful and cheaper in terms of development time, they still show up in generated api documentation quite a lot.

它们会导致问题,但在(很少)边缘情况下它们在开发时间方面可能有用且成本更低,它们仍然在生成的api文档中出现了很多。

But anyway, seeing as how you asked how to use them, here we go

但无论如何,看看你如何使用它们,我们走了

First up, it depends on whether you want to use a frameset, or just put some iframes into a page, iframes maybe easier, but will describe a frameset. Some references below. If you dig around the wayback machine on archive.org, you will get to see some examples, also Sun's online java docs used to be in framesets, but have not looked at them for years.

首先,这取决于你是想使用框架集,还是只是将一些iframe放入页面,iframe可能更容易,但会描述一个框架集。以下一些参考文献如果你在archive.org上挖掘回路机器,你会看到一些例子,Sun的在线java文档曾经是在框架集中,但多年来都没有看过它们。

http://www.w3schools.com/tags/tag_frameset.asp
http://www.w3schools.com/tags/tag_iframe.asp

Basically, the contents of each frame are individual pages, and the frames themselves must be named, within the file which contains the frameset, which might look a little like this:

基本上,每个帧的内容都是单独的页面,并且框架本身必须在包含框架集的文件中命名,这可能看起来像这样:

<html>
<frameset cols="25%,75%">
  <frame name="_left" src="nav.aspx" />
  <frame name="_right" src="foo.aspx" />
</frameset>
</html>

So, for the sake of the excercise, give the left frame attribute name="__left" and name="__right" for the right.

因此,为了练习,请为右侧提供左框架属性name =“__ left”和name =“__ right”。

Important bits about links
Any links inside your right frame that need to target that frame should have target= "_self", and any that need to escape the frame and set the location of the parent page, should have target="_top".

关于链接的重要部分右框内需要定位该框架的任何链接都应该有target =“_ self”,任何需要转义框架并设置父页面位置的链接都应该有target =“_ top”。

The links in your left frame will need to have the attribute target="_right", and that should load the appropriate document into the right frame when the link is clicked.

左侧框架中的链接需要具有属性target =“_ right”,并且应该在单击链接时将相应的文档加载到右侧框架中。

The rest of it is pretty much normal, treat the contents of your right hand frame as a normal page, make a master page as normal, all the normal html, head, body tags etc. There is nothing really different about frames in aspnet or php or anything else, its just html.

其余部分非常正常,将右侧框架的内容视为普通页面,使主页面正常,所有正常的html,头部,正文标签等.aspnet中的框架没有什么不同PHP或其他任何东西,它只是HTML。

There you have it, there may be a few things I have missed, because they're not something I use very often these days, but sometimes, when accessibility and all that don't matter, they can be a quick and dirty fix. e.g some obscure admin page on a web service site, that will get visited 12 times a year by a geek who understands what is going on.

你有它,可能有一些我错过的东西,因为它们不是我现在经常使用的东西,但有时,当可访问性和所有无关紧要时,它们可以是一个快速和肮脏的修复。例如,一个网站服务网站上的一些模糊的管理页面,每年会被一个了解正在发生的事情的极客访问12次。

So, they are evil, but that shouldn't stop you learning about them, you will get to really understand why they are evil, and form your own opinion as to when and when not to use them.

所以,它们是邪恶的,但这不应该阻止你了解它们,你将真正理解为什么它们是邪恶的,并形成你自己的意见,何时何时不使用它们。

#2


3  

Frames are generally frowned upon in modern web development for a few reasons (I won't get into them here). You're better off using CSS to make a 2 column layout. There are a lot of good tutorials on how to make layouts like this all over the web. One example can be found here:

在现代Web开发中,框架通常是不受欢迎的,原因有几个(我不会在这里介绍它们)。你最好使用CSS来制作2列布局。关于如何在整个网络上制作这样的布局,有很多很好的教程。可以在这里找到一个例子:

http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/

The example on that site looks like this:

该网站上的示例如下所示:

http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/finished.html

If you want the layout to fit on the screen, just define a height for #main. You just need to add this to your CSS after you're finished:

如果您希望布局适合屏幕,只需为#main定义高度。您只需在完成后将其添加到CSS中:

#main{height:600px}

Change the "600px" to whatever height you want if it doesn't fit for you.

如果它不适合您,请将“600px”更改为您想要的任何高度。

To use it on a master page, just make your master page follow the example above, and then make the inside of the #main <div /> tag your primary ContentPlaceholder

要在母版页上使用它,只需使您的母版页按照上面的示例操作,然后将#main

标记的内部作为主要ContentPlaceholder

#3


0  

The short and sweet answer?

短而甜蜜的回答?

Frames and framesets are no longer necessary or useful in web development, and they create many more problems than they solve.

框架和框架集在Web开发中不再是必需或有用的,它们会产生比它们解决的问题更多的问题。

In more detail:

更详细:

There's three things that you're probably using frames to help with:

有三件事你可能正在使用框架来帮助:

1) You want to have a navigation bar on the left, and have a separate content area on the right, basically vertical separation.

1)你想在左边有一个导航栏,右边有一个单独的内容区域,基本上是垂直分隔。

Non-frame solution:

Use regular HTML and CSS to create a 2 column layout. See some of the other resources or "The Last Guide to CSS Layout You'll Ever Need".

使用常规HTML和CSS创建2列布局。查看其他一些资源或“您需要的CSS布局最后指南”。

2) You want to be able to have one file with the navigation that you don't have to have a version of it on several different pages.

2)您希望能够拥有一个带有导航的文件,您不必在几个不同的页面上拥有它的版本。

Non-frame solution:

Keep the navigation in a seperate file, and just include it in all of your content pages. In ASP.NET, you can create a UserControl, or .ascx file and include it in all of your changes. Put your navigation in the UserControl and you only need to change it in one place.

将导航保存在单独的文件中,并将其包含在所有内容页面中。在ASP.NET中,您可以创建UserControl或.ascx文件,并将其包含在所有更改中。将导航放在UserControl中,您只需在一个位置更改它。

3) You want the quicker performance of only the content frame needing to reload, and not the navigation frame.

3)您希望仅更快地执行需要重新加载的内容框架,而不是导航框架。

Non-frame solution:

The extra time to load the whole page is negligible, and the simplicity of serving a single document at a time more than makes up for the tiny performance hit.

加载整个页面的额外时间可以忽略不计,并且一次提供单个文档的简单性足以弥补微小的性能损失。

#4


0  

you can put the iframe code on the body section. an example given below. try this :)

你可以把iframe代码放在body部分。下面给出一个例子。试试这个 :)

<iframe width="100%" height="600px" scrolling="no" seamless="yes" src="https://facebook.com"></iframe>