简体   繁体   English

调用An.aspx文件到另一个.aspx文件

[英]Calling An.aspx File Into Another .aspx File

I have an asp.net website and I want to know if its possible to call an .aspx file into another .aspx file. 我有一个asp.net网站,我想知道是否有可能将.aspx文件调用为另一个.aspx文件。 The scenario is that I have 3 left hand menus which are displayed on various pages. 场景是我有3个左手菜单,这些菜单显示在各个页面上。

At first I only had one left hand menu so this was added it to my Site.Master file but now I have and additional 2 left hand menus and rather than keep duplicating the code for these menu's in each relevant page, I want to know if there is a way I can create them and then call the relevant menu when the page loads. 最初我只有一个左手菜单,所以将其添加到我的Site.Master文件中,但是现在我还有另外两个左手菜单,而不是在每个相关页面中重复复制这些菜单的代码,我想知道是否有一种方法可以创建它们,然后在页面加载时调用相关菜单。

I could add each menu to my Site.Master and look for a specific word in my URL but this would add a lot of code to my Site.Master file which I'm not keen on as it will look messy. 我可以将每个菜单添加到Site.Master并在URL中查找特定的单词,但这会向Site.Master文件中添加很多代码,我不太喜欢它,因为它看起来很乱。

If it can be done, how do you do it? 如果可以做到,您将如何做?

You can use ASP.NET User Control to achieve this. 您可以使用ASP.NET User Control来实现此目的。 We have something similar where we've got a left menu on multple pages. 我们有很多类似的地方,在多个页面上都有一个左菜单。 Therefore what you will have to do is create the menu on the User Control and then use that control on each aspx page as required. 因此,您需要做的是在User Control上创建菜单,然后根据需要在每个aspx页面上使用该控件。 Regirster the control at the top of aspx page as aspx页面顶部的控件重新注册为

<%@ Register Src="~/PathTo/SomeMenu.ascx" TagPrefix="uc1" TagName="SomeMenu" %>

And then use it as 然后将其用作

<uc1:SomeMenu runat="server" ID="SomeMenu" />

Further reading here 在这里进一步阅读

yo can achieve this by using ASP.NET User Controls 可以通过使用ASP.NET用户控件来实现

or 要么

You can Use IFRAME 您可以使用IFRAME

<iframe name="myIframe" id="myIframe" src="some.aspx" width="400px" height="400px" runat =server></iframe>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM