(MVC) MVC (2017 год)

Expanding oportunities of Classic ASP.NET with generic extension function FindBaseClassRecursively.

Classic ASP.NET application often has not simple structure? cjmmon template is - there are Master page with incliding many controls, many pages with repiters and many levels including controls. But ASP.NET structure building by the way when function only in APP_CODE is accesible to all application, pages is placed in another folder and page function is not accesible from all application.

So, all common function of ASP.NET application moving to APP_CODE folder, and very often page has many level of inheritance hyerarhy. But how in control find needded class and simple cast it to fixed class? Expecially, if project in active development and imterface appears and diapperrs each days, new level of inheritance page is apears and disappears each days. I dont want to change page's control code each days, even if control in master page moving from one level to another. I want have stable page's control code and want have stability found method of master page's control.

In the screen below we may see common template of ASP.NET pages, this is very typical application.



For example in backet control placed in master page I have some needed interface to me, what simplest way to found it in control, that repeated in page? How to find method of basket, when button "Add to basket" will be pressed in first screen, of button "Cancel" in second screen?

And additionally, I need to know in control tabs number of paged, that cosist repeater of control (second screeh has three tabs). For this many purposes, I had write generic extension function for ASP.NET page:


   1:  Imports Microsoft.VisualBasic
   2:   
   3:  Public Module Extension2
   4:   
   5:      <Runtime.CompilerServices.Extension()> _
   6:      Public Function FindBaseClassRecursively(Of T As Class)(ByVal CurrentControl As Control) As T
   7:   
   8:          If TryCast(CurrentControl, T) IsNot Nothing Then
   9:              Return TryCast(CurrentControl, T)
  10:              Exit Function
  11:          Else
  12:              If CurrentControl.HasControls Then
  13:                  For Each c As Control In CurrentControl.Controls
  14:                      FindBaseClassRecursively(Of T)(c)
  15:                  Next
  16:              End If
  17:          End If
  18:   
  19:      End Function
  20:  End Module

With this function my code is simplified and come independence of adding level of inheritance of page and moving control from with needed function from one place of master page to another.





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17
Link to this page: http://www.vb-net.com/FindBaseClassRecursively/index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <MAIL ME>  <ABOUT ME>  < THANKS ME>