简体   繁体   中英

ASP.NET FormView DetailsView and polymorphism

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM