简体   繁体   English

从另一个aspx页面调用aspx,html页面

[英]Call aspx, html pages from another aspx page

I have one aspx page where I want to display contents of another aspx or html page based on the sessions. 我有一个aspx页面,我想根据会话在其中显示另一个aspx或html页面的内容。 Code behind logic will fetch the file from particular location based on the session. 逻辑代码会根据会话从特定位置获取文件。 I do not want to use frames, iframes because I have to make sure of cross browser compatibility. 我不想使用框架,iframe,因为我必须确保跨浏览器的兼容性。 Is there any other way to achieve this? 还有其他方法可以做到这一点吗?

User control may be a solution for this. 用户控制可能是解决方案。 I wanted to know more alternate approach. 我想知道更多替代方法。

Below is my code: 下面是我的代码:

I don't have anything in aspx except the references to the external js file. 除了对外部js文件的引用之外,aspx中没有任何内容。

Code behind: 后面的代码:

private void Page_Load(object sender, System.EventArgs e)
        {
            _getMainMenu();

        }
protected string _getMainMenu()
{
  string HomePageMenu = string.Empty;
 string homeExist = Server.MapPath("../homepages/" + Session["ACCOUNT"].ToString() + "/HomePage.htm");
                if (File.Exists(homeExist ))
                {
                    HomePageMenu = "../homepages/" + Session["ACCOUNT"].ToString() + "/HomePage.htm";
                }
                else
                {
                    HomePageMenu = "../homepages/NewMenu.html";
                }
return HomePageMenu ;
            }

Thanks. 谢谢。

Sounds like maybe something like jQuery load is something that may be helpful. 听起来像jQuery load之类的东西可能会有所帮助。 This will asynchronously retrieve content and place it into a control of your choice, and not necessarily an iframe of course. 这将异步检索内容并将其放入您选择的控件中,当然也不一定是iframe。 This is called from the client, but you can have your server side logic/session state determine the content returned. 这是从客户端调用的,但是您可以让服务器端逻辑/会话状态确定返回的内容。

You should change the way you manage your content in generally. 您应该更改总体上管理内容的方式。 In your case, your aspx-page is your content. 就您而言,您的aspx-page是您的内容。 And if you want to show contant b in contant a, you will have to show an aspx-page inside another aspx-page. 而且,如果要在常数a中显示常数b,则必须在另一个aspx-page中显示一个aspx-page。

Change the point of view: your aspx-page should only be your content-holder. 更改观点:aspx页应仅是内容所有者。 Extract your content to an ascx-usercontrol or store it in a database. 将您的内容提取到ascx-usercontrol或将其存储在数据库中。

Then you are able to fetch the content whereever you need them. 然后,您可以在任何需要的地方获取内容。

Showing an aspx-page inside another is a very bad solution. 在另一个页面内部显示一个aspx页面是一个非常糟糕的解决方案。

But if it's not possible to change the way your content is stored: I would prefere an iframe. 但是,如果无法更改内容的存储方式:我希望使用iframe。

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

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