How to add and link a cs file to an ASCX / ASPX page that does not have alrady?

I know a stupid question, but I tried to search it on Google without any luck.

+6
c # code-behind
source share
2 answers

Add the Inherits attribute to your <@Page directive with the class name provided in the cs file. For example:

 <@Page ... Inherits="MyNamespace.MyCustomPage"> 
+5
source share

As Jason already answered, also put "CodeFile = anycodefile.cs" in the page directive.

<@Page ... Inherits="MyNamespace.MyCustomPage" CodeFile="MyCustomPage.cs">

If your page has a code file, use the CodeFile attribute. Otherwise, put the assembly containing the code behind the class in the bin folder and use inheritance. The class should be based on a web page or user control and should be publicly available.

+2
source share

All Articles