How to add and bind a cs file to an ASCX/ASPX page that doesn't alrady have one?
Asked Answered
T

2

6

I know silly question but i tried looking it up on Google with no luck.

Transduction answered 10/9, 2009 at 17:26 Comment(1)
Are you going from a single file (i.e. inline code) to a code-beside file?Supranational
S
5

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

<@Page ... Inherits="MyNamespace.MyCustomPage">
Shiftless answered 10/9, 2009 at 17:31 Comment(0)
P
2

As Jason has already answered, also put a "CodeFile=anycodefile.cs" in the page directive.
<@Page ... Inherits="MyNamespace.MyCustomPage" CodeFile="MyCustomPage.cs">

If your page has a code-behind file, use the CodeFile attribute. Otherwise put the assembly containing the code behind class in the bin folder and use the inherits. The class must derive from webpage or usercontrol and must be public.

Pachydermatous answered 1/11, 2009 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.