ASP.NET
  Home arrow ASP.NET arrow Page 2 - 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: identifying requirements


    (Page 2 of 4 )

    In this section, I would like to introduce a new textbox control called "uctTextField." The "uct" stands for "User Control" as part of my naming convention. Let us consider the features not available with the existing Textbox server control (which is available as part of the ASP.NET framework).

    • It doesn't support labeling. You may have to add another label control to support the existing Textbox control.
    • To maintain some gap between Label and Textbox, you may have to work with TABLEs in HTML.
    • It doesn't have the "required input" option. You may have to add RequiredFieldValidator to the same Textbox control separately.
    • It doesn't have support for hints. Hints (or messages of format, etc.) are generally used when inputting dates and other items. You may have to add another Label control to support the same.
    • If I disable the Textbox, it simply locks the user out of the Textbox. But it doesn't automatically convert to Label (when in disabled mode).

    At the moment, I feel that these features are frequently used in every application. Now imagine what would happen if I have five textboxes on the web page. I have to create five labels, validators, hint labels, and read-only labels, working with layout and more. You may want to be able to implement your own features instead of (or in addition to) the ones I've described here. This scenario is always boring for any ASP.NET developer.

    To solve these "boring" problems, to a certain extent (or even to the full extent sometimes), user controls would be a great help. Now, I would like to design and develop a user control (called "uctTextField") supporting all of the above features. Once the control is developed, it can be dragged and dropped onto the web page any number of times, and it really improves my productivity.

    Developing your own flexible Textbox control with new features: the beginning

    Once you know the requirements for creating a new user control, it is time to implement the user control as part of your ASP.NET web solution. Using the Solution Explorer, right click on your solution and choose Add New Item. Within the Add New Item dialog box, select Web User Control as the template, provide the name of the User Control as "uctTextField" and hit Add.

    Drag and drop the controls (and other stuff) onto your user control, so that it looks likes the following in the source mode:

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="uctTextField.ascx.vb" Inherits="uctTextField" %>
    <asp:Panel ID="pnlControl" runat="server">
    <table cellpadding="0" cellspacing="0" border="0">
     
    <tr valign="top">
       
    <td style="white-space: nowrap">
         
    <asp:Panel ID="pnlText" runat="server" Visible="false"
    HorizontalAlign="Right">
           
    <asp:Label ID="lblText" runat="server" >Label:</asp:Label>
         
    </asp:Panel>
       
    </td>
       
    <td>
         
    <asp:Label ID="lblControl" runat="server" Width=""
    Visible="false"></asp:Label>
         
    <asp:TextBox ID="txtControl" runat="server"></asp:TextBox>
          <
    span
    id="spnRequiredIndicator" runat="server"
    class="requiredastrisk" visible="false">*</span>
          <
    asp:Panel ID="pnlHint" runat="server" Visible="false"
    HorizontalAlign="Left">
            <asp:Label ID="lblHint" runat="server" ></asp:Label>
         
    </asp:Panel>
        
    </td>
      
    </tr>
    </table>
    <asp:RequiredFieldValidator ID="reqfValidator" runat="server"
    ErrorMessage="[*name*] is required." ControlToValidate="txtControl"
    Display="None" Enabled="false"></asp:RequiredFieldValidator>
    </
    asp:Panel>

    According to the above source, you can understand that the entire control is a part of the Panel control. Within the panel, I created a simple HTML table to lay out all the controls in a convenient manner. The control mainly contains three Label controls, one Textbox control and one RequiredFieldValidator. For my convenience in layout, I added two more panels within the HTML table. The layout should look like the following in design mode (Fig 01).

    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 5 hosted by Hostway
    Stay green...Green IT