Are ASP.net Content web forms available for the variables listed in the "Code Behind" section of the main page?

I have a wizard page that controls the style of my site. Code Behind has several instance instances, as well as variables. These classes validate user access and then create user objects.

I have several forms of web content that execute instructions based on custom objects. It still seems that in every form of web content I need to create new instances of the classes found on the main page. This doubles my work for every form of web content.

Is there anyway I can not create classes and objects created in the code of the main page?

+3
source share
2 answers

Expose objects (and even controls) as public properties (receive only controls) on the page Master. Then on each page aspxyou want to access these objects, add the following declaration at the top:

<%@ MasterType VirtualPath="~/MyMasterPage.master" %>

As @Kristof points out, just access your properties, e.g. Master.PropertyName

, , Session ( , , DB ). Page, . , Master, Page usercontrol, ( CurrentUser) .

+8

, , . :

SiteMaster master = (SiteMaster)this.Master;
master.MyProperty = 0;

SiteMaster - . (SiteMaster )

, - ...

+2

Source: https://habr.com/ru/post/1777921/


All Articles