In this application I have a Login.aspx page with code behind. Now I would like to create
LoginLight.aspx lightweight version of Login.aspx page. The light version should have less HTML content and should use the key functions of
Login.aspx.vb code behind. These functions have a lot of code.
Therefore, in order not to have a lot of duplicate code, I would like to move the common functions to a common file. I was thinking about placing those functions in a class library in the
App_Code folder but I read on the web that is not a good solution.
I also read that to have the same code behind file for two different pages is not a good practice. How would I tackle this issue?
Whether it is a good programming practice or not, I would let yourself judge it and research it, however, if you make that one page inherits from the otherone, you would have only one code behind file for both pages. All the code and Event Handlers would
be placed in only one page, so you would need only to place the mark up in one page but writing the code in the other one (which would handle both). The Event Handlers in the inheriting page would have a green sign by intelisense stating a required overloading
of the base class file (the page from it is inheriting).
best practice is to make layered arcitechture. you can make a business logic layer for your appication. and you can create a class for userlogin. that will be accessable by all the application layer classes which you use the business layer's namespace. this
is really a gud practice to create a centralize logic.
Priyank Saxena
(Mark as Answer If you find helpful)
I read that if you place too much code in the App_code the performances of my application decrease. Morevoer the App_code folder is meant to contain utilities functions rather than business logic
I already use the three tier architecture. The problem in my case is that I am maintaining an already existing Web application which is coded in VB.NET. I create a two class libraries projects, one for the
Service Layer and one for the Repository Layer, coded in C#.
The code for authentication in Login.aspx has been developed around 2000 and you might guess how obsolete and "spaghetti" is. Building a Service and Repository components for logging in, requires a really deep analysis of the existing code
in Login.aspx in order to translate the code in C#, get rid of obsolete objects and functions and create methods in the Service Layer. I plan to do it in the future but at the moment it is out of project's scope
In my projects I have always used just Master pages. My notion of page inheritance of Web Pages is limited to this topic...can you point towards good articles where this topic is explained? However one of the reason I want to create a LoginLight.aspx page
is because Login.aspx uses a Master page and I do not want LoginLight to use it. I guess if I inherit the from Login.aspx page I also inherti from the Master page...
You can create a custom Usercontrol to login and load it in each page as needed also. That way you can load the control no matter which page is. That way you do not have to repeat code in each page, but only in the custom Usercontrol with the common functionality
you whish to use.
Marked as answer by Mark - MSFT on Jan 16, 2013 01:02 AM
TRINAKRIAE
Member
211 Points
147 Posts
Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 08, 2013 10:27 PM|LINK
I have an ASP.NET Web Forms application.
In this application I have a Login.aspx page with code behind. Now I would like to create LoginLight.aspx lightweight version of Login.aspx page. The light version should have less HTML content and should use the key functions of Login.aspx.vb code behind. These functions have a lot of code.
Therefore, in order not to have a lot of duplicate code, I would like to move the common functions to a common file. I was thinking about placing those functions in a class library in the App_Code folder but I read on the web that is not a good solution.
I also read that to have the same code behind file for two different pages is not a good practice. How would I tackle this issue?
KathyW
Participant
1666 Points
303 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 08, 2013 11:39 PM|LINK
" I read on the web that is not a good solution"
Why not?
otnielpena
Member
210 Points
38 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 08, 2013 11:45 PM|LINK
Whether it is a good programming practice or not, I would let yourself judge it and research it, however, if you make that one page inherits from the otherone, you would have only one code behind file for both pages. All the code and Event Handlers would be placed in only one page, so you would need only to place the mark up in one page but writing the code in the other one (which would handle both). The Event Handlers in the inheriting page would have a green sign by intelisense stating a required overloading of the base class file (the page from it is inheriting).
pradeep shar...
Contributor
4004 Points
763 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 09, 2013 04:26 AM|LINK
not it is not true- u can put the shared code in App_code there is no issue at all
priyankmtr
Contributor
2626 Points
526 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 09, 2013 04:43 AM|LINK
best practice is to make layered arcitechture. you can make a business logic layer for your appication. and you can create a class for userlogin. that will be accessable by all the application layer classes which you use the business layer's namespace. this is really a gud practice to create a centralize logic.
(Mark as Answer If you find helpful)
TRINAKRIAE
Member
211 Points
147 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 09, 2013 09:57 AM|LINK
I read that if you place too much code in the App_code the performances of my application decrease. Morevoer the App_code folder is meant to contain utilities functions rather than business logic
TRINAKRIAE
Member
211 Points
147 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 09, 2013 10:10 AM|LINK
I already use the three tier architecture. The problem in my case is that I am maintaining an already existing Web application which is coded in VB.NET. I create a two class libraries projects, one for the Service Layer and one for the Repository Layer, coded in C#.
The code for authentication in Login.aspx has been developed around 2000 and you might guess how obsolete and "spaghetti" is. Building a Service and Repository components for logging in, requires a really deep analysis of the existing code in Login.aspx in order to translate the code in C#, get rid of obsolete objects and functions and create methods in the Service Layer. I plan to do it in the future but at the moment it is out of project's scope
TRINAKRIAE
Member
211 Points
147 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 09, 2013 10:13 AM|LINK
In my projects I have always used just Master pages. My notion of page inheritance of Web Pages is limited to this topic...can you point towards good articles where this topic is explained? However one of the reason I want to create a LoginLight.aspx page is because Login.aspx uses a Master page and I do not want LoginLight to use it. I guess if I inherit the from Login.aspx page I also inherti from the Master page...
Thanks
ManikandanUl...
Participant
850 Points
253 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 09, 2013 10:24 AM|LINK
There is no issue to write code in App_code folder othere wise you can create common class in businesslogic and implement.
Click "…Mark As Answer" if my reply helpful....
otnielpena
Member
210 Points
38 Posts
Re: Where to place code shared between two pages in an ASP.NET Web Forms?
Jan 10, 2013 10:04 PM|LINK
Thinking more about the issue:
You can create a custom Usercontrol to login and load it in each page as needed also. That way you can load the control no matter which page is. That way you do not have to repeat code in each page, but only in the custom Usercontrol with the common functionality you whish to use.