Exforsys.com
 

Sponsored Links

 

ASP.NET Tutorials

 
Home Tutorials ASP.NET
 

ASP.NET Web Forms Controls

 

ASP.NET Web Forms Controls

Page 1 of 4

Introduction: In this tutorial we will introduce some of the most commonly used controls used in Asp.net web programming. We will see all the different types of controls and their behavior. I will not talk about complex, data bound or template controls in this tutorial since we are going to look at that in later tutorials.


Web Form Controls:

As in the previous tutorial I explained that there are three types of controls in Asp.net namely, HTML Controls, HTML Server Controls and Web Server Controls. Among these controls Web Server Controls are the most advanced controls and provides tons of features.

Input Controls:


Input controls are those controls which lets the user to interact with the underlying logic by providing input and than waiting for a response from the application. The most commonly used input control is TextBox control. Below you can see a small image of the TextBox control.



As you can see its just a blank box where you are write your desired input. TextBox control exposes many properties which you can use. In order to see the properties window just right click on the control and select properties. You will see the properties as seen in the image below.



You still must be wondering what other features TextBox control offers. Sometimes you need to write a lot of Text and need more place in the TextBox you can get more space by specifying the property of the TextBox TextMode to multiline which, allows you to enter unlimited text. You can also hide your input by specifying password in the TextMode property.



Now comes the cool part how can you access the text that you wrote in the TextBox. This is also as simple as "2+2". TextBox exposes a property which is "Text". You can use this property to either set or get the Text written in the TextBox. Here is the correct syntax of using the Text property.


Sample Code
  1. string myString = TextBox1.Text;
Copyright exforsys.com


this returns whatever was written in the TextBox. This is the most commonly used property of the TextBox control and is used most frequently.

You can also set the background color of the TextBox using the background color property in the property window. One important property I need to point out is the MaxLength property. The Maxlength property defines how many characters the Asp.net will take from the Textbox. But it does not limit the input while entering the Text. Meaning you can keep on writing on and Asp.net will not let you know that you have achieved the maximum characters in the TextBox. In order to stop the Text input behavior you will need to use the javascript to limit the number of characters input.

The id property of the TextBox specifies the unique id of a control on a page. Usually when dealing with TextBoxes the id starts with txt(YourSubject).

TextBox control also exposes some events. Now the events are generated when ever user interacts with the TextBox. Here are the events available for the TextBox control. Events are taken from "www.msdn.microsoft.com .


public eventDataBinding (inherited from Control) Occurs when the server control binds to a data source.
public eventDisposed (inherited from Control) Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.
public eventInit (inherited from Control) Occurs when the server control is initialized, which is the first step in the its lifecycle.
public eventLoad (inherited from Control) Occurs when the server control is loaded into the Page object.
public eventPreRender (inherited from Control) Occurs when the server control is about to render to its containing Page object.
public eventTextChanged Occurs when the content of the text box changes between posts to the server.
public eventUnload (inherited from Control) Occurs when the server control is unloaded from memory.


Next Page: ASP.NET Hyperlink Controls


Read Next: ASP .NET: Validating User Input with C#



 

 

Comments


wasiur_rahman said:

  Excellent article on Working with Web Forms Controls and C#. I really benefitted with the contents and was amazed to see this kind of extensive explanation on the topic which is quite rare on Net.......

Wasiur Rahman
April 22, 2005, 3:24 am

Ramaa said:

  good explanation ...thanks
November 3, 2006, 1:01 pm

nandamramu said:

  iam new learner of this topic.in
my view it is in very useful for selflearning students.
the author's way of illustration is appreciable.thanks for your efforts and helping.
November 9, 2006, 1:44 am

kavan said:

  I express thank you !
December 9, 2006, 5:19 am

Ganesh G said:

  :) Excellent article on Working with Web Forms Controls and C#.
February 28, 2007, 12:30 am

sksamantaray said:

  i m having 2 forms in c#.
Eachone is having a textbox control.
i want to retreive data of textbox of form1 to textbox of form2.
How do i do that,Can anyone help me?
April 30, 2007, 11:56 am

just a test article said:

  you can also take a look at this one
good article
May 9, 2007, 5:49 am

chithuraj said:

  very good easy to learn
May 13, 2007, 10:17 am

.netdeveloper said:

  very effective & usefull
June 7, 2007, 4:17 am

sherin raj said:

  Its really very useful for me to gain a lot of knowledge
December 19, 2007, 2:15 am

Samiullah said:

  Its really xlent for .net novice people...
April 3, 2008, 5:42 am

preethy mohan said:

  thank you for your valid information
December 4, 2008, 12:17 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape