ASP.NET
  Home arrow ASP.NET arrow Page 3 - Developing a Wonderful ASP.NET TextField C...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Developing a Wonderful ASP.NET TextField Control
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2007-03-14

    Table of Contents:
  • Developing a Wonderful ASP.NET TextField Control
  • Developing your own flexible Textbox control with new features: identifying requirements
  • Developing your own flexible Textbox control with new features: the skeleton
  • Developing your own flexible Textbox control with new features: coding properties

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing a Wonderful ASP.NET TextField Control - Developing your own flexible Textbox control with new features: the skeleton


    (Page 3 of 4 )

    Once the design is completed, we need to start coding. In the code behind, I followed the skeleton shown below:

    Imports System.ComponentModel

    <ControlValueProperty("Text"), _
     
    ValidationProperty("Text")> _
    Partial Class uctTextField
     
    Inherits System.Web.UI.UserControl
    .
    .
    #Region "Page Events"
    .
    .
     
    Public Overrides Sub Focus()

      Public Property Text() As String
     
    Public Property MaxLength() As Integer
     
    Public Property ErrorText() As String
     
    Public Property Editable() As Boolean
     
    Public Property Required() As Boolean
     
    Public Property LabelTextValue() As String
     
    Public Property LabelTextAlign() As
     
    Public Property LabelTextVisible() As Boolean
     
    Public Property LabelTextWidth() As System.Web.UI.WebControls.Unit
     
    Public Property AutoPostBack() As Boolean
     
    Public Property CssClassTextBoxControl() As String
     
    Public Property CssClassLabelControl() As String
     
    Public Property CssClassLabelText() As String
     
    Public Property Tooltip() As String
     
    Public Property ValidationGroup() As String
     
    Public Property HintMessage() As String
     
    Public Property HintMessageVisible() As Boolean
     
    Public Event TextChanged As EventHandler
    .
    .

    End Class

    I removed the code for clarity. Based on the discussion of the requirements in previous sections, I came up with the above list of properties, methods and events. You can modify the properties according to your naming conventions and standards. My intention is just to give you an idea of the list of features of the user control.

    Developing your own flexible Textbox control with new features: coding events

    I am currently using Page Events to simply maintain ViewState. The code is as follows:

    #Region "Page Events" 

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
       
    If IsPostBack Then
         
    Me.ErrorText = ViewState("ErrorText")
         
    Required = ViewState("Required")
       
    End If
     
    End Sub

     Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.PreRender
     
    ViewState("ErrorText") = ErrorText
     
    ViewState("Required") = Required
    End Sub

    #End Region

    The only method I used is the Focus method. When the control receives the focus, the cursor should be available in the text box. If the control is in read-only mode, it will not be able to receive any focus. It is defined as follows:

    Public Overrides Sub Focus()
     
    If Editable Then txtControl.Focus()
    End Sub

    Our control should also be supporting TextChanged event, and I created it as follows:

    #Region "Events"
     
    Public Event TextChanged As EventHandler
     
    Protected Sub txtControl_TextChanged(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles txtControl.TextChanged
       
    Me.Text = txtControl.Text
       
    RaiseEvent TextChanged(sender, e)
     
    End Sub
    #End Region

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! The article fully concentrates on the development of a well-featured...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT