c# - 如何将 aspx 页面加载到 webpart

标签 c# asp.net sharepoint-2010 web-parts

我通常这样做是为了从布局目录加载网络用户控件。

protected override void CreateChildControls()
{
     try
     {

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
           base.CreateChildControls();
           string strControlReference = "/_layouts/Controls/MyCustomControl.ascx";

           //instantiate the user control
           MyCustomControl ucControl = (MyCustomControl)Page.LoadControl(strControlReference);

           //add the control to webpart
           this.Controls.Add(ucControl);
        });
     }
     catch (Exception ex)
     {
        Common.WriteLogEvent(ex);
     }

}

现在我想做的是,我在 layouts 文件夹下有一个 web 表单“_/layouts/Page/MyPage.aspx”文件,我想加载这个文件而不是在 webpart 页面上加载一个典型的 ascx 文件.

这可能吗?我想知道怎么做。谢谢。

最佳答案

您可以添加 <IFRAME>到 Web 部件并将页面加载到其中。

或者创建 IFRAME以编程方式添加它,并以与添加用户控件相同的方式添加它:

var pageUrl = .....; // URL to your page
var literal = new Literal();
literal.Text = string.Format("<iframe src='{0}'></iframe>", pageUrl);
this.Controls.Add(literal);

关于c# - 如何将 aspx 页面加载到 webpart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796188/

相关文章:

c# - 从 mysql 填充数据网格特定定义的列

c# - 如何使用反射调用方法并传递编译时类型未知的参数?

c# - 创建 C# 属性类/为不同类型返回特定属性的策略是什么?

sharepoint - 通过互联网访问 Infopath 表单

jquery - 希望在 SharePoint 中检索用户组

c# - 如何延迟 Unity 和 C# 中的方法?

c# - 无法将类型 'Microsoft.AspNetCore.Mvc.NotFoundResult' 隐式转换为 'System.Threading.Tasks.Task'

c# - 无法找到请求的.Net Framework 数据提供程序。可能没有安装。(informix)

asp.net - TeamCity 使用 MSDEPLOY ERROR_FILE_IN_USE

asp.net - 如何使用 WSP 将 Asp.net Web 应用程序部署到 Sharepoint 2010 站点