我在动态创建页面时遇到了一些问题:
p = New Page();
Page myPage = new Page();
FormAtt ctrl = (FormAtt)myPage.LoadControl("path/to/my/file.ascx"); // here lies the gridview of evil
myPage.Controls.Add(ctrl);
问题是我收到了
Control ... must be placed inside a form tag with runat=server
好的,所以我发现我需要覆盖 VerifyRenderingInServerForm
方法才能调用无格式页面,但是我该如何覆盖 VerifyRenderingInServerForm
因为我没有 ASPX 文件。
ps:我有一个相关的问题,但我不知道该怎么办,因为它们是不同的问题,但解决方案针对的是同一个问题,我放弃了最后一个解决方案 - 请参阅:Form is Null in Dynamically created Pages
最佳答案
您可以尝试使用已经覆盖 VerifyRenderingInServerForm
的自定义类:
public partial class MyCustomPage : System.Web.UI.Page
{
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Page_Load(object sender, EventArgs e)
{
var p = new MyCustomPage();
FormAtt uc = (FormAtt)p.LoadControl("path/to/my/file.ascx");
p.Controls.Add(uc);
}
}
关于c# - 在动态创建的 Pages() 上覆盖 VerifyRenderingInServerForm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14957374/