ASP.NET LoadControl 使用关键字“base”; 在此上下文中无效
我想要一个 Web 服务来加载 .ascx 控件,在其中加载一些值,然后返回该控件的 HTML 内容。 我有类似的东西:
[WebMethod(EnableSession = true)]
public void GetHTML()
{
UserControl loader = new UserControl();
MyCustomReport reportControl =
(MyCustomReport)loader.LoadControl("~/The/path/to/the/.ascx");
reportControl.DataBind();
return "TODO";
}
MyCustomReport 覆盖 DataBind()
:
public override void DataBind()
{
base.DataBind();
// etc.
}
行 base.DataBind()
抛出 NullReferenceException
并且调试器显示:
在此上下文中使用关键字“base”无效
任何帮助将不胜感激,谢谢!
I want a web service to load an .ascx control, load some values in it and then return the HTML content of this control. I have something like that:
[WebMethod(EnableSession = true)]
public void GetHTML()
{
UserControl loader = new UserControl();
MyCustomReport reportControl =
(MyCustomReport)loader.LoadControl("~/The/path/to/the/.ascx");
reportControl.DataBind();
return "TODO";
}
MyCustomReport overrides DataBind()
:
public override void DataBind()
{
base.DataBind();
// etc.
}
The row base.DataBind()
throws a NullReferenceException
and the debugger says:
Use of keyword 'base' is not valid in this context
Any help will be appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
UserControl
< /a> 没有虚拟DataBind
方法,但有虚拟OnDataBinding
方法。 我相信这是您想要重写的方法。Try this:
UserControl
does not have a virtualDataBind
method but it does have a virtualOnDataBinding
method. I believe this is the method you mean to override.