Create A Simple Component

Components enable you to encapsulate business logic that can be reused across several applications. You can create managed classes in C# or any other .NET compliant language to create your reusable components.

The process for creating a simple component starts with creating a C# source file. In this source file you first declare the namespace for the classes contained in the source file. In your C# source file, you need to add functions to hold your business logic. For instance, in the simple component example you have a function, called SayWelcomeStatement, that returns the same string message to any caller. Note as well that you create an alias to the System namespace in the C# source file.

When you finish creating the code, you need to compile the program using the csc command at the command prompt. You use this compiler to create a DLL with your source code. To use the component on Web pages in your site, you need to place the compiled DLL in the /bin directory of the Web site. To reference the component, you need to import the namespace that you specified in the source file. After you have done this, you can create an instance of the class created and call functions in that class.

CREATE A SIMPLE COMPONENT

CREATE A SIMPLE COMPONENT

□ Open a new document in your text editor.

L0 Create a new namespace.

-0 Add an alias to the System namespace.

—Q Create a public class.

0 Create a public function that returns a string variable.

-0 Return a message to the caller.

Q Save the file.

□ Open a new document in your text editor.

L0 Create a new namespace.

-0 Add an alias to the System namespace.

—Q Create a public class.

0 Create a public function that returns a string variable.

-0 Return a message to the caller.

Q Save the file.

Note: In this example, the file is being saved to the default Web site location at C:\InetPub\wwwroot.

Was this article helpful?

0 0

Post a comment