ASP.NET FormView DetailsView 和多态性
我正在编写一个 ASP.NET 母版页,它执行主/详细信息编辑的常见繁琐工作(ValidationSummary、错误处理、使用 jQuery-ui 对话框弹出详细信息视图)。它有两个用于主视图和详细视图的 ContentPlaceHolder
控件,主占位符预计包含一个 GridView
,而详细占位符则包含一个 DetailsView
或 FormView
。
母版页只需要访问DetailsView 或FormView 的一些基本成员:
- ChangeMode 方法
- DataBind 方法
- CurrentMode 属性
- InsertItem 方法
- UpdateItem 方法
我很惊讶地发现,虽然DetailsView 和FormView 都有这些相同的成员,但它们却没有(DataBind 除外) )从公共基类或接口继承。甚至还有两个等效的枚举 FormViewMode
和 DetailsViewMode
,因此 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,它们是:
DetailsView:CompositeDataBoundControl、IDataItemContainer、INamingContainer、ICallbackContainer、ICallbackEventHandler、IPostBackEventHandler、IPostBackContainer、IDataBoundItemControl、IDataBoundControl、IFieldControl
FormView:CompositeDataBoundControl、IDataItemContainer、INamingContainer、IPostBackEventHandler、IPostBackContainer、IDataBoundItemControl、IDataBoundControl、IRenderOuterTableControl
Yes they are:
DetailsView : CompositeDataBoundControl, IDataItemContainer, INamingContainer, ICallbackContainer, ICallbackEventHandler, IPostBackEventHandler, IPostBackContainer, IDataBoundItemControl, IDataBoundControl, IFieldControl
FormView : CompositeDataBoundControl, IDataItemContainer, INamingContainer, IPostBackEventHandler, IPostBackContainer, IDataBoundItemControl, IDataBoundControl, IRenderOuterTableControl