ASP.Net Multiple Source Files

in uncompiled .aspx, is it possible to have 2 partial class files for one aspx? I am trying to do something like:

    <% @ Page 
        Language = "C #" 
        inherits = "_ Default" 
        src = "Default.aspx.cs" 
        src = "Default2.aspx.cs"%>

Both default and default2 have a specific partial class

Update: Yes .. This does not compile or the item would be a moot point, how would I just throw the appropriate dll into the / bin directory. I need this to not be compiled, because the source should change regularly. I could probably come up with a way to simply upgrade aspx, but I would not want to.

The reason I use the two source files is because there is a lot of source code that connects to my database and something else. I have one person who will guess with db stuff and another person to guess with different logic. I would prefer these files to be split, so they don’t need to get confused through code that they don’t need to look for

+3
source share
3 answers

Yes and no. Yes, you can have as many partial classes as you wish. No, you cannot (and should not!) List them on your page.

<%@ Page 
        Language="C#" 
        inherits="Default" %>

in Default.aspx.cs:

public partial class Default
{ /*yadda*/ }

in Default2.aspx.cs:

public partial class Default
{ /* even more yadda */ }

- . CLR. # ; asp.net .


, , . / . db , , , "", DI.

, ; , . DI . Unity DI . , .

+6

, Src .

+1

Without answering your question, do you consider inheritance from the base page to merge code?

In your Default.aspx.cs file:

public partial class Default : CustomBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

In your CustomBasePage.cs:

public class BasePage: System.Web.UI.Page
{
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        //Your custom code
    }
}

If you need to override event methods, etc. in the default.aspx.cs file, be sure to call the base methods.

0
source

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


All Articles