ASP.NET Textbox Control

The Textbox control is used to get information from the user. You can define the look of the textbox using the properties and you can validate the text once the user clicks a button. Just like many other controls you can control whether a textbox is visible or not.

Textbox Appearance:

More than likely you have seen a textbox on a web page and most likely have entered text into it. Textboxes do not have to be plain and simple. You can change the many properties of the textbox to so that it you can design the appearance to match your web page color scheme. Show below are just a few examples of the different ways you can style your asp.net textbox.


    txtbox.backcolor="orange"

    txtbox.bordercolor="blue"

    txtbox.borderstyle="dotted"

    txtbox.borderwidth-="3px" txtbox.borderstyle="dashed"

   txtbox.forecolor="blue"    txtbox.text="mytext"

Capturing Text from the textbox:

After your user enters information into the textbox you need to retrieve that information. The most common way to retrieve the information is with a button event which causes a page postback. Below is an example of a simple interactive web piece that demonstrates how to retrieve textbox data and use it in your feedback to the user. Notice that on page post back I also make the button disappear.

 

What is your name?  

Below is the code that made that little interation possible.

ASP.NET

        
<asp:Label ID="lblQuestion" runat="server" Text="What is your name?" />
<asp:TextBox ID="txtYourName" runat="server" />
<sp:Button ID="btnYourName" runat="server" style="background-color:White; 
font-size:smaller;" Text="DONE" Width="35px" />         
        

VB.NET

                   
Protected Sub btnYourName_Click(ByVal sender As Object, 
      ByVal e As System.EventArgs) Handles btnYourName.Click 

    lblQuestion.Text = "Hi, " + txtYourName.Text + "! I am glad you are 
      interested in ASP.NET textbox controls. Textboxes let you easily 
      interact with users on your site." 

    txtYourName.Visible = False 

    btnYourName.Visible = False

End Sub