VS2005 - Declaring page objects in the business layer
-
In 2003 I would pass a page object and other information to the business layer so that common functionality can be execute in one location for all pages. e.g. validating users, setting up menus, setting the webform state (editmode/readonly), etc... However, in VS2005 I am unable to declare variables in the business layer as a webform, masterpage or usercontrol. I even changed the partial class to public for those web types. Is there a work-around I am missing? Below the following user controls and master pages cannot be declared to a variable: IAC.Training.usercontrols.pagetabs, IAC.Training.Web.MasterMain. Error is 'Type ... is not defined'. Basically, just about every page would access the following code to create the webform's menus/submenus. There is no sense in placing the code in every form. Any ideas?
Namespace IAC.Training.BusinessLayer
Public Class Search
Inherits BusinessLogicLayerSearchBaseSub New(ByVal uID As Integer, ByVal page As Control) MyBase.new(uID, page) End Sub Public Sub InitializeMenus(ByVal currentTabName As String) Dim page As Page = CType(Me.Page, Page)'From the base class Dim subTabs As IAC.Training.usercontrols.pagetabs = page.FindControl("subTabs", IAC.Training.usercontrols.pagetabs) 'Load Menus CType(page.Master, IAC.Training.Web.MasterMain).InitMenu(True, IAC.Training.Web.MasterMain.MenuTabs.Search.ToString) subTabs.DataSource = SubTabCollection() subTabs.IsChildMenuTabs = True subTabs.CurrentTabName = currentTabName subTabs.DataBind() End Sub
Thanks, Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970) -- modified at 12:00 Wednesday 12th April, 2006
-
In 2003 I would pass a page object and other information to the business layer so that common functionality can be execute in one location for all pages. e.g. validating users, setting up menus, setting the webform state (editmode/readonly), etc... However, in VS2005 I am unable to declare variables in the business layer as a webform, masterpage or usercontrol. I even changed the partial class to public for those web types. Is there a work-around I am missing? Below the following user controls and master pages cannot be declared to a variable: IAC.Training.usercontrols.pagetabs, IAC.Training.Web.MasterMain. Error is 'Type ... is not defined'. Basically, just about every page would access the following code to create the webform's menus/submenus. There is no sense in placing the code in every form. Any ideas?
Namespace IAC.Training.BusinessLayer
Public Class Search
Inherits BusinessLogicLayerSearchBaseSub New(ByVal uID As Integer, ByVal page As Control) MyBase.new(uID, page) End Sub Public Sub InitializeMenus(ByVal currentTabName As String) Dim page As Page = CType(Me.Page, Page)'From the base class Dim subTabs As IAC.Training.usercontrols.pagetabs = page.FindControl("subTabs", IAC.Training.usercontrols.pagetabs) 'Load Menus CType(page.Master, IAC.Training.Web.MasterMain).InitMenu(True, IAC.Training.Web.MasterMain.MenuTabs.Search.ToString) subTabs.DataSource = SubTabCollection() subTabs.IsChildMenuTabs = True subTabs.CurrentTabName = currentTabName subTabs.DataBind() End Sub
Thanks, Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970) -- modified at 12:00 Wednesday 12th April, 2006
Because the compiling model is changed in the ASP.NET 2.0, so I think you cannot access the dynamic class (of the web page, master page or the user control) in a custom class like that. Here are a couple of options come to mind: + You can place your sample code in a web page, user control or master page, then use the Reference[^] directive to programmatically access the classes like the pagetabs, MasterMain ... + You may think of creating the base class for the master page or user control so that you can use this base class in your business layer. + Because you said every page would access that sample code, so IMHO you may place the code right in the master page and the user control.
-
Because the compiling model is changed in the ASP.NET 2.0, so I think you cannot access the dynamic class (of the web page, master page or the user control) in a custom class like that. Here are a couple of options come to mind: + You can place your sample code in a web page, user control or master page, then use the Reference[^] directive to programmatically access the classes like the pagetabs, MasterMain ... + You may think of creating the base class for the master page or user control so that you can use this base class in your business layer. + Because you said every page would access that sample code, so IMHO you may place the code right in the master page and the user control.
Thanks. I was hoping I was simply missing something quick & easy to implement the techniques. The app is ported from version 1.1 of .net As far as the reference directive, the pages already have them for the controls. I knew I could create base classes or interfaces but again was hoping not to have to go through all of the pages. Putting the code in the master page is something I didn't think about. I take a look at possibly putting the common code here away from the business layer. Thanks I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
-
Thanks. I was hoping I was simply missing something quick & easy to implement the techniques. The app is ported from version 1.1 of .net As far as the reference directive, the pages already have them for the controls. I knew I could create base classes or interfaces but again was hoping not to have to go through all of the pages. Putting the code in the master page is something I didn't think about. I take a look at possibly putting the common code here away from the business layer. Thanks I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
I ended up using both interfaces and base classes to create the functionality needed to interact with the webtype classes with in the business layer.
Public Interface IMasterPage
Sub InitMenu(ByVal hasChildMenuTabs As Boolean, ByVal currentTabName As String)
End InterfacePublic Sub InitializeMenus(ByVal currentTabName As String) 'MasterPage menus 'Uses the IMasterPage inteface CType(MyBase.Page.Master, IAC.Training.Web.IMasterPage).InitMenu(True, currentTabName) 'Current page menus uses the inherited BaseTabMenu to expose the needed methods in the usercontrol Dim subTabs As IAC.Training.Web.BaseTabMenu = CType(Page.FindControl("subTabs"), IAC.Training.Web.BaseTabMenu) With subTabs .CurrentTabName = currentTabName .IsChildMenuTabs = True .DataSource = SubTabCollection() .DataBind() End With End Sub
Thanks again Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970) -- modified at 11:02 Thursday 13th April, 2006
-
Thanks. I was hoping I was simply missing something quick & easy to implement the techniques. The app is ported from version 1.1 of .net As far as the reference directive, the pages already have them for the controls. I knew I could create base classes or interfaces but again was hoping not to have to go through all of the pages. Putting the code in the master page is something I didn't think about. I take a look at possibly putting the common code here away from the business layer. Thanks I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
Hi Michael, There is another option that you might also want to try, I mean you can try the VS 2005 Web Project[^] which is an add-in for VS 2005 (it's still RC though). With this option, you may not change your code, and you can easily access the classes of the web page and user control as you would with VS 2003, :cool:!