ASP.NET FormView DetailsView 和多态性

发布于 2025-01-04 10:03:20 字数 729 浏览 1 评论 0原文

我正在编写一个 ASP.NET 母版页,它执行主/详细信息编辑的常见繁琐工作(ValidationSummary、错误处理、使用 jQuery-ui 对话框弹出详细信息视图)。它有两个用于主视图和详细视图的 ContentPlaceHolder 控件,主占位符预计包含一个 GridView,而详细占位符则包含一个 DetailsViewFormView

母版页只需要访问DetailsView 或FormView 的一些基本成员:

  • ChangeMode 方法
  • DataBind 方法
  • CurrentMode 属性
  • InsertItem 方法
  • UpdateItem 方法

我很惊讶地发现,虽然DetailsView 和FormView 都有这些相同的成员,但它们却没有(DataBind 除外) )从公共基类或接口继承。甚至还有两个等效的枚举 FormViewModeDetailsViewMode,因此 ChangeMode 和 CurrentMode 成员甚至不具有相同的签名。

我打算通过创建一个包装类来解决这个问题,但是任何人都可以解释为什么它们是这样实现的吗?我是否通过尝试多态性地使用它们而积累了麻烦?

我很难相信这不是微软工程师故意的,所以我只能得出结论,他们打算阻止多态性的使用。

I'm writing an ASP.NET Master Page that does the common grunt work for master/detail editing (ValidationSummary, error handling, popup of detail view using jQuery-ui dialog). It has two ContentPlaceHolder controls for the master and detail views, the master placeholder is expected to contain a GridView, and the detail placeholder either a DetailsView or a FormView.

The master page just needs to access a few basic members of the DetailsView or FormView:

  • ChangeMode method
  • DataBind method
  • CurrentMode property
  • InsertItem method
  • UpdateItem method

I was surprised to see that, while both DetailsView and FormView have these same members, they are not (except DataBind) inherited from a common base class or interface. There are even two equivalent enums FormViewMode and DetailsViewMode, so that the ChangeMode and CurrentMode members don't even have the same signature.

I am intending to get round this by creating a wrapper class, but can anyone explain why they are implemented like this? Am I storing up trouble by attempting to use them polymorphically?

I find it hard to believe that this was not deliberate on the part of Microsoft's engineers, so I can only conclude that they intended to discourage polymorphic use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莫言歌 2025-01-11 10:03:20

虽然DetailsView和FormView都有这些相同的成员,但它们是
不是从公共基类或接口继承的。

是的,它们是:

DetailsView:CompositeDataBoundControl、IDataItemContainer、INamingContainer、ICallbackContainer、ICallbackEventHandler、IPostBackEventHandler、IPostBackContainer、IDataBoundItemControl、IDataBoundControl、IFieldControl

FormView:CompositeDataBoundControl、IDataItemContainer、INamingContainer、IPostBackEventHandler、IPostBackContainer、IDataBoundItemControl、IDataBoundControl、IRenderOuterTableControl

while both DetailsView and FormView have these same members, they are
not inherited from a common base class or interface.

Yes they are:

DetailsView : CompositeDataBoundControl, IDataItemContainer, INamingContainer, ICallbackContainer, ICallbackEventHandler, IPostBackEventHandler, IPostBackContainer, IDataBoundItemControl, IDataBoundControl, IFieldControl

FormView : CompositeDataBoundControl, IDataItemContainer, INamingContainer, IPostBackEventHandler, IPostBackContainer, IDataBoundItemControl, IDataBoundControl, IRenderOuterTableControl

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文