question

CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 asked SamWu-MSFT commented

How to make use of Partial Class Files

I hope this is simple! When I use Visual Studio, I can create separate files of the codebehind file (in my case, Default.aspx.cs)., all based on the "partial" keyword.
But when I set up everything in a typical IIS environment, I don't know how to get the aspx file to "see" those separate files.

Can this be done? If so, how do you do it?

Thank you in advance!

windows-server-iisdotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SamWu-MSFT avatar image
0 Votes"
SamWu-MSFT answered SamWu-MSFT commented

Hi @CoreyFleig-6304

When you deploy .aspx pages, if their associated code-behind class files are precompiled, you only have to deploy the assembly to the Bin folder of the application. You do not have to deploy the actual code-behind class files with the application.

When you deploy .aspx pages, if their associated code-behind class files are not precompiled, you must deploy the code-behind class files with the application. Additionally, you must add the Src attribute to the @ Page directive because the class file must be available when it is compiled on demand.

More information about code-behind class file you can refer to this link: code-behind-class-files.


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Now I understand Sam. Thanks.
For testing I don't pre-compile. I need to see the code, so I just place the files in the project directory.

But when I read the docs on @page directives, It seems I need to include "src=file1.cs" maybe?

How do I declare that page?

0 Votes 0 ·

@CoreyFleig-6304 You can refer to this code: <%@ Page language="c#" Codebehind="SrcSample.aspx.cs" AutoEventWireup="false" Inherits="CodeBehindSamples.SrcSample" Src="SrcSample.aspx.cs"%>

0 Votes 0 ·

Sam,
Please forgive me - I am sure I asked my question incorrectly. I should restate the problem I have. I hope you'll bear with me.

I have a project with two files;

Default.aspx
Default.aspx.cs (public partial class Default : System.Web.UI.Page)

The Default.aspx.cs file has 7 methods, and in VS2019 I separated those out into their own files (for example, DoWork1.cs, DoWork2.cs, DoWork3.cs, etc.).
Each file has "public partial class Default".

So in a classic IIS project environment with no pre-compiled DLLs, can I get Default.aspx to recognize those 7 additional code files?

0 Votes 0 ·

@CoreyFleig-6304 Have you considered putting these 7 methods into the Default.aspx.cs file? Then your problem is gone.

0 Votes 0 ·
CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 answered SamWu-MSFT commented

Yes - that's what I'm doing now. I wanted to know if I can separate them out, however.
If it's a problem, or ASP.NET is not built for that as I've described, that would be helpful to know as well.

Can it be done?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@CoreyFleig-6304 I'm not sure because I didn't find a way to do this.

0 Votes 0 ·