ARTICLE

Using Component (Private Access Modifier) in ASP.Net: Part 4

Posted by Abhimanyu Kumar Vatsa Articles | ASP.NET using VB.NET August 06, 2010
This is my series of articles on ASP Components and in this article we will discuss how to declare fields using Private access modifier for components.
Reader Level:

Introduction

Here is Part 3

It is very-very lazy way to create a property is to create a public field. For simple application it is good but if you are working on very secure application then it is very important to point out all such points too. Here in this article we will be using Private access modifier.

Component4.gif

Class1.vb File Code

Imports Microsoft.VisualBasic

Public Class Class1
    Private WelcomeMsg As
String

    Public Property Message() As String
        Get
            Return WelcomeMsg
        End Get
        Set(ByVal Value As String)
            If Value.Length > 5 Then
                Throw New Exception("Message too long!")
            End If
            WelcomeMsg = Value
        End Set
    End
Property

    Public Function SayMessage() As String
        Return WelcomeMsg
    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 msg As New Class1
        msg.Message = "Welcome to MINDCRACKER"
        Label1.Text = msg.SayMessage
    End
Sub
End Class

Now look at the above code we have used

If Value.Length > 5 Then
      Throw New Exception("Message too long!")
End If

In above code we have limited the Message size by 5. But the message we have used it longer then 5 characters. This will cause a server side error. We have to increase the message length as per actual message size.

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
 
Team Foundation Server Hosting
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.
    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. Visit DynamicPDF here
Nevron Diagram
Become a Sponsor