Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » ASP.NET 2.0/3.5 » Fundamental of ASP.NET controls with examples

Fundamental of ASP.NET controls with examples

In this article, you will learn about the fundamentals of ASP.NET including some of its controls with the help of examples.

Author Rank :
Page Views : 3211
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Team Foundation Server Hosting
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

In this article we will learn the fundamental of ASP.NET controls. Some new controls are added in ASP.NET 2.0. These controls also discussed in this article. There are the following controls uses in ASP.NET.

Label:

It is the simplest of all controls and is required for almost all applications you develop. It will show what you should enter inside the text box or what to pick from the drop down box.

<asp:Label ID="Label1" runat="server" Text="Label" Width="110px"></asp:Label>

For Example:

<asp:Label ID="Label1" runat="server" Text="User Name" Width="110px"> </asp:Label></div>

The attribute id denotes the name for a specific control. This is of not much importance for the Label control but it is required for other controls such as Buttons, DropDownList as you will make use of the relevant controls during the coding phase.

TextBox:

This control is mainly used to accept text from the end user. You have the option to set three different modes such as:

  • SingleLine
  • MultiLine
  • Password

Let us examine each of these modes with sample code.

SingleLine mode

<asp:TextBox id="TextBox1" runat="server">This is TextBox</asp:TextBox>

MultiLine mode

<asp:TextBox id="TextBox1" runat="server" TextMode="MultiLine">This is the multiline textbox</asp:TextBox>

Password mode

<asp:TextBox id="TextBox1" runat="server"TextMode="Password"> </asp:TextBox>

CheckBox:

This control is used to select one or more options by putting a checkmark near the word.

<asp:CheckBox ID="CheckBox1" runat="server"text="dotnet"Checked=true/> <br><br><br>

 

<asp:CheckBox ID="CheckBox2" runat="server"text="jave"Checked=false/> <br><br><br>

<asp:CheckBox ID="CheckBox3" runat="server"text="sqlserver" Checked=true/> 

If you set checked property to True as shown in the above code then that checkbox will be automatically selected when you run the ASP.NET page.

RadioButton:

This control is used to select only one choice from a list of various entries.

<asp:RadioButton id="RadioButton1" runat="server" Text="USA" GroupName="Countries"></asp:RadioButton>

<asp:RadioButton id="RadioButton2" runat="server" Text="UK" GroupName="Countries"></asp:RadioButton>

You should note that GroupName property is important for the proper functioning of RadioButton control. If you fail to set this property then you will be able to select both the options.

DropDownList:

DropDownList is one of the popular controls used in each ASP.NET application. Users can pick an option by clicking on the drop down arrow.

<asp:DropDownList id="DropDownList1" runat="server">
<
asp:listitem id= "lstaspdotnet" runat= "server">ASP.NET</asp:listitem>
<
asp:listitem id= "lstvbnet" runat= "server">Visual Basic .NET</asp:listitem>
<
asp:listitem id= "lstjava" runat= "server">Java</asp:listitem>
<
asp:listitem id= "lstperl" runat= "server">PERL</asp:listitem>
</
asp:DropDownList>

In the above code, we have given the various options inside the <asp:listitem></asp:listitem> tag. You can add any number of this tag for each item that you wish to include inside the DropDownList. You should note that users can pick only one option using this control.

ListBox:

ListBox is an extension to the above mentioned WebForm control. With the help of this control, you can select one or more options by holding the Control key.

<asp:ListBox id="ListBox1" runat="server" SelectionMode="Multiple">
<
asp:ListItem Value="ASP.NET">ASP.NET</asp:ListItem>
<
asp:ListItem Value="Visual Basic .NET">Visual Basic.NET</asp:ListItem>
<
asp:ListItem Value="Java">Java</asp:ListItem>
<
asp:ListItem Value="PERL">PERL</asp:ListItem>
</
asp:ListBox>

You should set the value of SelectionMode property to Multiple as shown in the code given above. By default, its value is Single and you can select only one option.

CheckBoxList:

CheckBoxList is a group of CheckBoxes arrange in a ListBox. It is a very similar to that of the ListBox control.

<asp:CheckBoxList id="CheckBoxList1" runat="server">
<
asp:ListItem Value="ASP.NET">ASP.NET</asp:ListItem>
<
asp:ListItem Value="Visual Basic .NET">Visual Basic .NET</asp:ListItem>
<
asp:ListItem Value="Java">Java</asp:ListItem>
<
asp:ListItem Value="PERL">PERL</asp:ListItem>
</
asp:CheckBoxList>

Link Button:

This control is similar to that of Button control but it displays the text as a hyperlink.

<asp:LinkButton id="LinkButton1" onclick="LinkButton1_Click" runat="server">Click here</asp:LinkButton>

In the code above, there is an event handler called onclick. When a user clicks the link button control, necessary action will take place depending upon the code you have given by double clicking the control.

Table:

You can create tables using the Table control. This control uses the TableRow and TableCell controls available within the .NET Framework.

<asp:Table id="Table1" runat="server" GridLines="Both">

<asp:TableRow>
<
asp:TableCell Text="Sl No"></asp:TableCell>
<
asp:TableCell Text="Name"></asp:TableCell>
</
asp:TableRow>

<asp:TableRow>
<
asp:TableCell Text="1"></asp:TableCell>
<
asp:TableCell Text="Rob"></asp:TableCell>
</
asp:TableRow>

<asp:TableRow>
<
asp:TableCell Text="2"></asp:TableCell>
<
asp:TableCell Text="Mark"></asp:TableCell>
</
asp:TableRow>

</asp:Table>

The above code may look complicated but you will find it easier to use it after a little practice. The GridLines property takes four different values such as None, Horizontal, Vertical and Both. The value both denotes a combination of Horizontal and Vertical lines.

Calendar:

With the help of the Calendar control, you can navigate through months and dates and select them. The selected entry can then be displayed on a Label control as shown in the code given below.

<asp:Calendar ID="Calendar1" runat="server" BackColor="#FF80FF" BorderColor="Blue"

BorderStyle="Outset"   VisibleDate="2007-04-30"> </asp:Calendar>

Output of this code is as follow:

Figure 1: Calendar

Calendar control comes with lot of properties which you can use to display the control in various formats.

The .NET Framework 2.0 ships with lot of WebForm controls which can be used for various purposes. We will discuss about some of them in the next part of this series.

GridView:

This is one of the most popular controls used by majority of developers for database operations. You can edit, delete records using GridView.

<asp:GridView ID="GridView1" runat="server"></asp:GridView>

           

Figure 2: GridView

DetailsView:

This control is used to display one record from a database at a time. You can also insert records using DetailsView.

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px">

</asp:DetailsView>

Figure 3: Detailsview

FormView:

With GridView, you can display all the records from a database. But with the help of FormView control, you can show only one record at a time but you have the ability to insert new records.

The main difference between DetailsView and FormView controls is that FormView has more options. You can have control over how to display data, modify headers and footers and much more.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Purushottam Rathore

I am working as a Software Developer and has 4 years of experience on Microsoft Technology and having a Master Degree in Computer Application. I really like to work in the .NET platform. and working with ASP.NET 2.0/3.5, Web Services, WPF, WCF, Silverlight, AJAX, JavaScript, JQuery, Ado.net, MsAccess, SQL Server 2005/2008.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
Vai by Michael On July 5, 2010
Vai, Apna ai da ki post korsen............
Reply | Email | Modify 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.