Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

ASP.NET Web Forms Controls

By Exforsys | on February 26, 2005 |
ASP.NET

Working with Web Forms Controls and C# covers Introduction to Web Forms Controls, Simple Input Controls, HyperLinks and Button Controls and List Controls

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.

  1.      string myString = TextBox1.Text; 
  2.      // 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 thePage 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.

 

}

Hyperlink Controls:

Hyperlinks controls are those controls that drink a lot of coffee and that’s why they always remain Hyper. Hyperlink controls are used to link one page to the other page. If you drag and drop the hyperlink control from the toolbox to the webform your Hyperlink control will look something like this:

Hyperlink exposes many important properties. One of them is NavigateUrl. NavigateUrl is used to give the path to the next linking page. The hyperlink also exposes the property of ImageUrl which can be used to assign the image to the hyperlink. Each control also comes with a tooltip property. The tooltip property can be used to make a message appear when a user hover his mouse pointer over the hyperlink.

The available events for the hyperlink controls are given below:

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 thePage object.
public eventPreRender (inherited from Control) Occurs when the server control is about to render to its containing Page object.
public eventUnload (inherited from Control) Occurs when the server control is unloaded from memory.

{mospagebreak title=ASP.NET Button Controls}

Button Controls:

Button control is also one of the most important control available for developing Asp.net forms. When ever you submit a form you need a button to tell Asp.net parser that you have completed the form that’s the basic purpose of the button control. Apart from the display properties and appearance of the button control the most important event raised is button click event.

Here is what the button click event looks like:

  1. private void Button2_Click(object sender, System.EventArgs e) {
  2.  
  3. 	}

Here the name of the button is Button2, which is the id of the button. The button event takes two parameters which are object sender and System.EventArgs.

the object sender specifies that which button on the form has been clicked. And the next parameter System.EventArgs tells the asp.net that what is being send to the button method.

Below is the list of all the events supported by button control.

Public Events

 

public eventClick Occurs when the Button control is clicked.
public eventCommand Occurs when the Button control is clicked.
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 thePage object.
public eventPreRender (inherited from Control) Occurs when the server control is about to render to its containing Page object.
public eventUnload (inherited from Control) Occurs when the server control is unloaded from memory.

 

Lets make a small application that will change the text in the TextBox when the button is clicked.

  1. private void Button2_Click(object sender, System.EventArgs e) {
  2. 	TextBox1.Text = "This is my new Text";
  3. }

As you see its very simple to raise and capture, capture and take action on the event.

{mospagebreak title=ASP.NET List Controls}​

List Controls:

List controls provide the user with a number of options to choose from. A user has a choice to select a single option or list of options. The ListBox control provided by Asp.net controls collection. The listbox control has a collection property which is known as items. You can click on the property and populate the ListBox with the data and the value you desire. While populating the ListBox remember that the Text property of the ListBox is the text which will appear inside the it and the value is simple value. Usually we set the value to an integer which maps to some column in the database. Lets see how we can select a simple item in the ListBox control.

  1. private void ListBox2_SelectedIndexChanged(object sender, System.EventArgs e) {
  2.      string selectedItemTextFromListBox = ListBox1.SelectedItem; 
  3.      // Returns the text
  4.      string selectedItemValueFromListBox = ListBox1.SelectedValue; 
  5.      // returns the value
  6. }

The listbox exposes the property of SelectedItem and SelectedValue which can be used to find the selected item or selected value. You can also set the SelectionMode of the ListBox to multiple which allows the user to select multiple items with the ctrl key being pressed while selecting. Here is a small piece of code you can use to find out all the selected items in the listbox.

  1. private void ListBox2_SelectedIndexChanged(object sender, System.EventArgs e) {
  2.      foreach(ListItem l in ListBox1.Items) {
  3.           if(l.Selected) {
  4.                selectedItems += l.Text;
  5.                selectedValue += l.Value;
  6.           }
  7.      }
  8. }

The foreach loop will iterate the collection and if it finds the selected item it will assign to the string.

In the next tutorial we will see more advanced controls. 

References:

www.msdn.microsoft.com
www.asp.net

« « Data Warehouse database and OLTP database
Oracle 9i PL/SQL Control Structures » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • ASP .NET Migration and Interoperability

    April 24, 2005 - 0 Comment
  • Managing State with ASP.NET and C#

    May 3, 2005 - 0 Comment
  • ASP.NET with C# Training Launch

    February 19, 2005 - 0 Comment
  • Caching in ASP.NET

    May 9, 2005 - 0 Comment
  • Introduction to ASP.NET with C#

    February 20, 2005 - 0 Comment
  • Configuring and Deploying ASP.NET Applications

    May 14, 2005 - 0 Comment
  • ASP.NET with C# Training Course Outline

    February 19, 2005 - 0 Comment
  • Securing ASP.NET Applications with C#

    May 14, 2005 - 0 Comment
  • ASP .NET: Validating User Input with C#

    March 4, 2005 - 0 Comment
  • Using Rich Server Controls with C#

    March 12, 2005 - 0 Comment
  • Securing ASP.NET Applications with C#

    May 14, 2005 - 0 Comment
  • Configuring and Deploying ASP.NET Applications

    May 14, 2005 - 0 Comment
  • Caching in ASP.NET

    May 9, 2005 - 0 Comment
  • Managing State with ASP.NET and C#

    May 3, 2005 - 0 Comment
  • ASP .NET Migration and Interoperability

    April 24, 2005 - 0 Comment
  • Creating and consuming XML Web Services with C#

    April 14, 2005 - 0 Comment
  • Managing Data with ADO.NET DataSets and C#

    April 8, 2005 - 0 Comment
  • ASP.NET Using the DataList and Repeater, Datagrid Controls

    March 26, 2005 - 0 Comment
  • Accessing Data with C#

    March 19, 2005 - 0 Comment
  • Using Rich Server Controls with C#

    March 12, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Securing ASP.NET Applications with C#
  • Configuring and Deploying ASP.NET Applications
  • Caching in ASP.NET
  • Managing State with ASP.NET and C#
  • ASP .NET Migration and Interoperability

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT