IDE
Visual Studio 2019
Scenario
I was trying to create a public class and add it to a webform.
Solution
After researched a bunch of materials, I finally figured the simple way to do it.
In Class file
- Create an ASP.NET folder"App_Code" in your project.
- Create a class file in the folder "App_Code".
- Declared the class as a public class and type your methods there.
- Right-click the class file to properties
- Look for "Build Action", change it to "Compile"
In webform
- Go back to the webform that you wanted to add a class file and type "using webForms.App_Code;" at the top of the page.
- There you go! Now you can reference your public class file anywhere you want!
Top comments (0)