Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place code shared between two pages in an ASP.NET Web Forms?

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 for two different pages because it is not a good practice. How would I tackle this issue?

like image 460
CiccioMiami Avatar asked Nov 24 '25 18:11

CiccioMiami


1 Answers

Create a base page that has all the functionality that you want shared.

Login.aspx and LoginLight.aspx will both inherit that base page.

like image 182
Shai Cohen Avatar answered Nov 27 '25 08:11

Shai Cohen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!