ASP.NET
  Home arrow ASP.NET arrow Page 2 - ASP.NET Custom Server Controls: Cute ASP.N...
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

ASP.NET Custom Server Controls: Cute ASP.NET TextBox Control
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2005-08-30

    Table of Contents:
  • ASP.NET Custom Server Controls: Cute ASP.NET TextBox Control
  • Developing the “MyTextBox” Control
  • Testing the control with a Web Application
  • Understanding the MyTextBox
  • Handling the “PostBack” from “ViewState”
  • Is it cute? How can we make it cute?

  • 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


    ASP.NET Custom Server Controls: Cute ASP.NET TextBox Control - Developing the “MyTextBox” Control


    (Page 2 of 6 )


    Now, we will develop a simple “Textbox” type of control right from scratch. I call it “MyTextBox” throughout this article. The following steps help you to create the custom control using Visual Studio.NET 2003.


    • Click start -> Programs -> Microsoft Visual Studio .NET 2003 ->Microsoft Visual Studio .NET 2003 to open the IDE (Integrated Development Environment).

    • Click File -> New -> Project.

    • Within the “new project” dialog box select “visual basic projects” as the project type, “Web Control Library” as the template and provide the name “SimpleCustomControl” along with the location you desire (Figure:1), and finally click “ok.”

    • Within the solution explorer, right-click on “WebCustomControl1.Vb” and select “delete” to delete it.

    • Go to the project menu and select “Add New Item.”

    • Within the “Add New Item” dialog box select “WebCustomControl” and name it “MyTextBox.vb.”

    • Modify code (or just copy and paste) in the editor as follows:


    Imports System.ComponentModel

    Imports System.Web.UI


    <DefaultProperty("Text"), ToolboxData("<{0}:MyTextBox runat=server></{0}:MyTextBox>")> Public Class MyTextBox

    Inherits System.Web.UI.WebControls.WebControl

    Implements IPostBackDataHandler



    Property [Text]() As String

    Get

    Return viewstate("text") & ""

    End Get


    Set(ByVal Value As String)

    viewstate("text") = Value

    End Set

    End Property


    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

    MyBase.AddAttributesToRender(output)

    output.AddAttribute (HtmlTextWriterAttribute.Name, Me.UniqueID)

    output.AddAttribute (HtmlTextWriterAttribute.Id, Me.ClientID)

    output.AddAttribute (HtmlTextWriterAttribute.Type, "text")

    output.AddAttribute (HtmlTextWriterAttribute.Value, Text)

    output.RenderBeginTag (HtmlTextWriterTag.Input)

    output.RenderEndTag()


    End Sub


    Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.
    NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData

    If Text <> postCollection(Me.UniqueID) Then

    Text = postCollection(Me.UniqueID)

    Return True

    End If

    Return False

    End Function


    Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.
    RaisePostDataChangedEvent


    End Sub

    End Class



    • Press Shift+CtrI+B to build the solution


    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Communicate with your network of business associates, agents, dealers and clients...
       · Is your post, having any relation with my article? I hope this is not an...
       · Hello guys, this is my article on creating a Cute ASP.NET textbox control. You can...
     

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