ARTICLE

Using Component (Creating Basic Component) in ASP.Net: Part 1

Posted by Abhimanyu Kumar Vatsa Articles | ASP.NET using VB.NET August 05, 2010
This is my series of articles on ASP Components and in this article we will discuss how to create basic component.
Reader Level:

Introduction

As we know components enable us to reuse application logic across multiple pages or even say across multiple applications. We can write a method named GetConnection() once and use this method in all the pages consist in website. By taking advantage of components, we can make our applications very easier to maintain, execute, reuse and even extend the use in multiple aspects. But if we are working on simple website project, there is no reason to take advantage of components.

In this article series we will discuss how to build simple and advanced components. I am writing this series in multiple parts. If we are working on Components then we also have to discuss on its methods, properties, constructors, inheritance and interfaces.

Basic Component

In this basic component we will create simple welcome application suing components. Here is the example given below.

Component1.gif

Class1.vb File Code

Imports Microsoft.VisualBasic

Public Class Class1
    Public Function Welcome() As String
        Return "Welcome to MINDCRACKER"
    End
Function
End Class

Default.aspx File Code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title
>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
  
     <asp:Label ID="Label1" runat="server" Text=""></asp:Label
>

       </div>
    </form
>
</body>
</
html>

Default.aspx.vb File Code

Partial Class _Default
    Inherits System.Web.UI.
Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim showMessage As New Class1()
        Label1.Text = showMessage.Welcome()
    End
Sub
End Class

In the Page_Load() event handler, an instance of the Class1() component is created. Next, the result returned by a call to the Welcome() method is assigned to a Label control. When we open the page in your browser, we'll see the message "Welcome to MINDCRACKER" from the Class.vb File.

Note: Continue in Next Part.

HAVE A GREAT CODING!
 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor