我通常这样做是为了从布局目录加载网络用户控件。
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/