ASP.NET
  Home arrow ASP.NET arrow Page 2 - Extending the ASP.NET TextField User Contr...
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

Extending the ASP.NET TextField User Control
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 17
    2007-03-21

    Table of Contents:
  • Extending the ASP.NET TextField User Control
  • Developing your own flexible NumericTextbox control: the beginning
  • Developing your own flexible NumericTextbox control: coding events
  • Developing your own flexible NumericTextbox control: properties to retrieve values

  • 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


    Extending the ASP.NET TextField User Control - Developing your own flexible NumericTextbox control: the beginning


    (Page 2 of 4 )

    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 "uctNumericTextField" 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="uctNumericTextField.ascx.vb" Inherits="uctNumericTextField" %>
    <%@ Register Src="uctTextField.ascx" TagName="uctTextField" TagPrefix="uc1" %>
    <asp:Panel ID="pnlControl" runat="server"><uc1:uctTextField ID="utxtControl" runat="server" />
      
    <asp:RegularExpressionValidator ID="regExpValidator" runat="server" ControlToValidate="utxtControl"
         
    Display="None" ErrorMessage="[*name*] must be valid." ValidationExpression="^d+(?:.d{0,2})?$"></asp:RegularExpressionValidator>
      
    <asp:CustomValidator ControlToValidate="utxtControl" ID="cstmValidator" runat="server" Display="None" ErrorMessage="Value not in range"></asp:CustomValidator></asp:Panel>
    <asp:Label ID="lblInfo" runat="server" Text="TextField Numeric"></asp:Label>

    According to the above source, you can understand that the entire control is again a part of the Panel control. Within the panel, I created two validators (a Regular Expression validator and a Custom Validator), uctTextField and a Label. Make sure that the path of "uctTextField.ascx" is set properly. The layout should look like the following in design mode (Fig 01):

    Developing your own flexible NumericTextbox control: the skeleton

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

    Imports System.ComponentModel

    <ControlValueProperty("Text"), _
     
    ValidationProperty("Text")> _
    Partial Class uctNumericTextField
     
    Inherits System.Web.UI.UserControl
    .
    .

    #Region "Page Events"
    .
    .
      Public Overrides Sub Focus()
      Private Sub ApplyRegExpValString()
      Private Property RegExpValString() As String
      Public Property IncludeThousandsSeparator() As Boolean
      Public Property DecimalPlaces() As Integer
      Public Property MaxLength() As Integer
      Public Property MaxValue() As Decimal
      Public Property MinValue() As Decimal
      Public Property Text() As String
      Private Function UnFormattedValue(ByVal strValue As String) As String
      Private Function FormattedValue(ByVal strValue As String) As String
      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
    .
    .
    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. I removed the TextChanged event from this control. If you need it, you can add it as explained in my previous article.

    You could also observe that a few of the properties in the previous user control (uctTextField) also got repeated here. That is necessary as we need to map the same existing functionality of uctTextField to this control. 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.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,This is an extension to my previous contribution focusing on...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - 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

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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