You are on page 1of 16

4/23/22, 1:04 PM ASP.

NET UNIT-1

ASP.NET - UNIT 1
SYLLABUS :
UNIT I : ASP.NET Basics Introduction to ASP.NET: .NET Framework (CLR, CLI,
BCL), ASP.NET Basics, ASP.NET Page Structure, Page Life Cycle. Controls: HTML Server
Controls, Web Server Controls, Web User Controls, Validation Controls, Custom Web Controls.

1.1 INTRODUCTION TO .NET Framework


The .NET Framework is a software framework developed by Microsoft. The .NET runs on
Microsoft Windows. It provides language interoperability and can run across several programming
languages and platforms. Programs written for the .NET Framework execute in a software
environment, known as the Common Language Runtime (CLR). CLR is an application virtual
machine that provides services such as security, memory management, and exception handling. The
class libraries and the CLR together constitute the .NET Framework.
The .NET Framework's Base Class Library provides user interface, data access, database
connectivity, cryptography, web application development, numeric algorithms, and network
communications.

1.2 DESIGN FEATURES OF .NET


Interoperability .NET Framework provides access to newer and older programs that
execute outside the .NET environment. Access to COM components is provided in the
System.Runtime.
Common Language Runtime engine Common Language Runtime (CLR) serves as the
execution engine of the .NET Framework. All .NET programs execute under the supervision
of the CLR, guaranteeing certain properties and behaviors in the areas of memory
management, security and exception handling.
Language independence The .NET Framework has Common Type System(CTS). CTS is
used to support all datatypes and programming constructs supported by the CLR Because of
CTS, the .NET Framework supports the exchange of types and object instances between
libraries and applications written using any conforming .NET language.
Base Class Library The Base Class Library (BCL), is part of the Framework Class Library
(FCL). It is a library of functionality available to all languages using the .NET Framework.
The BCL provides classes that encapsulate a number of common functions, including file
reading and writing, graphic rendering, database interaction, XML document manipulation,
and so on. It consists of classes, interfaces of reusable types that integrates with CLR.
Simplified deployment The .NET Framework includes design features and tools which
help manage the installation of computer software to ensure it does not interfere with
previously installed software.
Security .NET provides a common security model for all applications. It eliminates the
vulnerabilities, such as buffer overflows, which have been exploited by malicious software.
Additionally,
Portability .NET framework is platform independent and cross-platform implementations
are available for other operating systems.

1.3 EVOLUTION OF .NET

csresources.in/aspnotes/aspnet_unit1.htm 1/16
4/23/22, 1:05 PM ASP.NET UNIT-1

Framework Versions /Tools used Features


.NET Framework 1.0 First version of .NET Framework.
(February 2002)
.NET Framework 1.1 C# Version: 1.2 · ASP.NET and ADO.NET updates
(April 2003) · Side by side execution
CLR Version: 1.1 · .NET Compact framework
· Secure coding guideline
· Information about application
deployment
.NET Framework 2.0 C# Version: 2.0 · 64-bit platform support
(November 2003) · Access Control List Support
CLR Version: 2.0 · Data Protection APIs
· Detecting changes in network
Development Tool : Visual connectivity
Studio 2005 · FTP Support
· Web Services
.NET Framework 3.0 C# Version: 3.0 · Windows Communication
(November 2006) CLR Ver: 2.0 Foundation
Dev Tool: Visual Studio · Windows Presentation Foundation
2005 · Windows Forms
.NET Framework 3.5 C# Version: 3.0 · ASP.NET Ajax enabled Websites
(November 2007) · LINQ
CLR Version: 2.0 · Dynamic DataCollections
· Time Zone Improvements
Development Tool : Visual · Cryptography Enhancements
Studio 2008 · Web Service interoperability
.NET Framework 4.0 C# Version: 4.0 · Expanded Base Class
(April 2010) · Cross-Platform Development with
CLR Version: 4 portable class library
Development Tool : Visual · Dynamic Language Runtime
Studio 2010 · Parallel Computing
.NET Framework 4.6 C# Version: 6.0 · Compilation Using .NET Native
(July 2015) CLR Version: 4.0 · ASP.NET Core 5
Development Tool : Visual · HTTP/2 Support
Studio 2015 · 64-bit JIT Compiler for managed
code
· SSL Support
.NET Framework 4.7 C# Version: · Enhanced cryptography with elliptic
(April 2017) CLR Version: 4.0 curve cryptography.
Development Tool : Visual · Support for High-DPI awareness
Studio 2017 support in Windows Forms.
· More support for touch and stylus in
Windows Presentation Foundation.
.NET Framework 4.8 C# Version: · Runtime – JIT improvements.
(April 2019) CLR Version: 4.0 · Runtime – Antimalware Scanning.
Development Tool : Visual · Windows Forms – Accessibility
Studio 2019 Enhancements.

csresources.in/aspnotes/aspnet_unit1.htm 2/16
4/23/22, 1:05 PM ASP.NET UNIT-1

Table 1 : Evolution of .NET (Reference Wikipedia)

1.4 COMMON LANGUAGE INFRASTRUCTURE (CLI)


Common Language Infrastructure (CLI) provides a language-neutral platform for
application development and execution, including functions for Exception handling, Garbage
Collection, security, and interoperability.
By using the features of the .NET Framework within the scope of the CLI, the
functionality will be available across all the languages supported by the framework. Microsoft's
implementation of the CLI is called the Common Language Runtime, or CLR.
The CIL code is housed in CLI assemblies. CLI assemblies are stored in the Portable
Executable (PE) format for all DLL and EXE files.
The complete name of an assembly contains its simple text name, version number,
culture, and public key token. Assemblies are considered equivalent if they share the same
complete name, excluding the revision of the version number.

1.5 . ASP.NET
ASP.NET, the next version of ASP, is a programming framework used to create enterprise-class Web
Applications. These applications are accessible on a global basis leading to efficient information

csresources.in/aspnotes/aspnet_unit1.htm 3/16
4/23/22, 1:05 PM ASP.NET UNIT-1

management.

1.6 Advantages of using ASP.NET


ASP.NET reduces the amount of code required to build large applications ASP.NET
applications runs faster and counters large volumes of users without performance problems.
ASP.NET makes development simpler and easier to maintain with an event-driven, server-side
programming model
ASP.NET pages are easy to write and maintain because the source code and HTML are
together.
The source code which is executed in the server is compiled the first time the page is
requested. Execution is fast as the Web Server compiles the page the first time it is requested.
The server saves the compiled version of the page for use next time the page is requested .
The HTML produced by the ASP.NET page is sent back to the browser. The application
source code is not sent and is not easily stolen .
ASP.NET facilitates for easy deployment. There is no need to register components because the
configuration information is built-in.
The Web server continuously monitors the pages, components and applications running on it.
If it notices memory leaks, infinite loops, other illegal software or activities, it seamlessly kills
those activities and restarts itself.
ASP.NET validates information (validation controls) entered by the user without writing a
single line of code.
ASP.NET works with ADO .NET for connecting to databases and data-binding.

1.7 DIFFERENCES BETWEEN ASP.NET AND CLIENT-SIDE


TECHNOLOGIES
Client-side refers to browser and the machine running the browser. Server-side refers to Web server.
Client-Side Scripting JavaScript and VBScript are generally used for Client-side scripting
and it is executed in the browser after the page is loaded. Both, HTML and the script are together in
the same file and the script is downloaded as part of the page. A client-side script runs only on a
browser that supports scripting and specifically the scripting language that is used. Since the script is
in the same file as the HTML and as it executes on the machine you use, the page may take longer
time to download.
Server-Side Scripting ASP.NET is purely server-side technology. ASP.NET code executes on the
server before it is sent to the browser. The code that is sent back to the browser is pure HTML and
not ASP.NET code. Like client-side scripting, ASP.NET code is written alongside HTML. Unlike
client-side scripting, ASP.NET code is executed in server and not in the browser. The script that is
present along with HTML is not sent back to the browser and that prevents others from stealing the
code.

1.8 FEATURES OF ASP.NET


ASPX,ASP Up gradation of ASP to ASPX is not required it supports side by side
execution and hence a request can be given from ASP to ASPX and vice versa.

csresources.in/aspnotes/aspnet_unit1.htm 4/16
4/23/22, 1:05 PM ASP.NET UNIT-1

Simplified Programming Model ASP.Net is a technology which can be implemented


using any dot net language such as VB.net,C# etc and hence there is no requirement of
HTML, JavaScript or VBScript to implement ASP.NET
Simplified deployment ASP.Net supports setup and deployment and hence the web app
can be defined with a web set up project which can be easily deployed on to the web server. In
for ASP CUTE FTP is used for deploying, it is required to upload manually.
Better Performance Since ASPX pages are complier based the performance of the web
application will be faster than the ASP pages (as they are interpreter based)
Caching It is a process of maintaining the result or output of a web page temporarily for
some period of time .ASP supports Client Side caching where as ASP.Net supports both client
side and server side.
Security In ASP security is done by IIS or writing the code manually. In ASP.Net it is
defined with built in security features such as
* windows authentication * Forms Authentication
* Passport Authentication * Custom Authentication
More powerful data access ASP.net supports ADO and ADO.Net as its database
connectivity model which will be implemented using the most Powerful OOP’S languages like
VB.Net and C# and hence the database access using ASPX pages will be very powerful.
Web services It is a code which will be published on the web which can be used by any
applications written using any language for an platform or device.
Better session Management Session Management in ASP.Net can be maintained using the
database and cookieless sessions are also supported. It also supports enabling and disabling of
session info within a web application.
Simplified Form Validations ASP.Net provides validation controls using which any type of
client side validations are performed without writing any code.

1.9 ARCHITECTURE OF ASP.NET


A web page is in 2 parts
1} Designing part (HTML Content,Flash,Dreamweaver etc)
2} logic Part (sub programs and event procedures and it has also your database interaction)

ASP.Net supports 2 techniques for creating web page


1) In Page Technique when you place design part code and logic part code with in a single
file called as ASPX then it is called as inPage Technique.
2) Code Behind Technique when design part code is represented with in ASPX file and logic
part code is represented with in dll file then it is called as code behind technique.
ASP Supports only In Page technique.
DLL file is not a readable file so it is secured.

csresources.in/aspnotes/aspnet_unit1.htm 5/16
4/23/22, 1:05 PM ASP.NET UNIT-1

Inet_info.exe à identifies the request and submits the request to the aspnet_isapi.dll.
Aspnet_isapi.dll à is a script engine which process the .aspx page
Then the script engine will submit the request to the ASP.NET runtime env.
After verifying all the security issues of both machine.config and web.config then an
AppDomain will be defined for the request and after processing the request the response will
be given to the client as HTTP response.
Machine.Config à it is used to maintain the complete configuration details of all the web
applications registered on to the web server of ASP.net
Web.Config à It is used to maintain the config details about a single web application.
Configuration details includes security, database connectivity, state management, trace
details of the web application, authentication and authorization of the applications and
globalizations.
AppDomain: All windows applications run inside a process and these process own resources
such as memory and kernel objects. All the applications are run on high isolation mode to
work safely. The disadvantage of this is memory resources are blocked. So to achieve this in a
single process all the applications should be made to run which is good to an extent. In .net the
code verification feature takes care that the code is safe to run, so asp.net each application runs
its own application domain.
HTTPHandlers: ASP.net is built on extensible architecture known as HTTP runtime. This is
responsible for handling the requests and sending the response. IS supports a low level API

csresources.in/aspnotes/aspnet_unit1.htm 6/16
4/23/22, 1:05 PM ASP.NET UNIT-1

known as ISAPI. ASP.net implements a similar concept with HTTP handlers. A request is
assigned to ASP.net from IIS then ASP.net examines entries in the <httphandlers> section
based on the extension of the request to determine which handler the request should be send
to.

1.10 The Structure of an ASP.NET Page


The important elements of an ASP.NET page are:
· Directives
· Code declaration blocks
· ASP.NET controls
· Code render blocks
· Server-side comments
· Server-side include directives
· Literal text and HTML tags

Directives A directive controls the compilation of ASP.NET. The directive begins with the
characters <%@ and the end of a directive is marked with the characters %>. These instructions
include registering a custom control, page language etc. It describes how the .aspx pages (web
forms) or .ascx pages (user controls) are processed by the .net framework.
A directive can appear anywhere within a page. By convention, however, a directive typically
appears at the top of an ASP.NET page.
There are several types of directives that can be added to an ASP.NET page. Two of the most
useful types are page and import directives.

Page Directives A page directive is used to specify the default programming language for a
page. Page directives can also be used to enable tracing and debugging for a page.
To change the default programming language of an ASP.NET page from Visual Basic to C#, for
example, you would use the following page directive:
<%@ Page Language="C#" %>

NOTE : The keyword Page in a page directive is optional. The following two directives are
equivalent: <%@ Page Language="C#" %>
<%@ Language="C#" %>

TRACE DIRECTIVE : If Trace directive is enabled, for a page, additional information about the
execution of the page is displayed along with the content of the page. Tracing can be enabled for a
page by including the following directive:
<%@ Page Trace="True" %>
After enabling tracing for a page, trace messages can be displayed by using two methods of the
Trace class: Write() and Warn(). Either of these methods can be used to display custom message in
the trace information displayed at the bottom of the page. The only difference between the two
methods is that the former method displays messages in black text, and the latter method displays
messages in red text, which is easier to see.
DEBUG DIRECTIVE To enable runtime error messages to be displayed on a page, the Debug
directive is used. To display errors in ASP.NET page, the following directive is included:
<%@ Page Debug="True" %>

csresources.in/aspnotes/aspnet_unit1.htm 7/16
4/23/22, 1:05 PM ASP.NET UNIT-1

If this directive is included, when an error is encountered while processing the page, the error is
displayed. In most cases, we can view source code for the exact statement that generated the error.
To enable both tracing and debugging for a page, combine the directives like this.
<%@ Page Debug="True" Trace="True" %>
IMPORT DIRECTIVES By default, only certain namespaces are automatically imported into
ASP.NET page. Inorder to refer to a class that isn't a member of one of the default namespaces, the
namespace must be explicitly imported or t use the fully qualified name of the class.
For example, to send an email from an ASP.NET page by using the Send method of the SmtpMail
class, SmtpMail class is to added as an Import directive. The SmtpMail class is contained in the
System.Web.Mail namespace. This is not a default namespace imported into an ASP.NET page.
The following page shows how to import the System.Web.Mail namespace and send email message.
ImportNamespace.aspx
<%@ Import Namespace="System.Web.Mail" %>
<Script Runat="Server">
Sub Page_Load
Dim mailMessage As SmtpMail
mailMessage.Send( "bob@somewhere.com", "Sending Mail!", "Hello!" )
End Sub
</Script>
<html>
<head><title>ImportNamespace.aspx</title></head>
<body>
<h2>Email Sent!</h2>
</body>
</html>
The first line in the above Listing contains an import directive. Without the import directive, the
page would generate an error because it would not be able to resolve the SmtpMail class.
@ assembly The @assembly directive attaches assemblies to the page or an asp.net user control
thereby all the assembly classes and interfaces are available to the class. This directive supports the
two attributes name and src. The name attribute defines the assembly name and the src attribute
defines the source of the assembly.
@ control Defines control-specific attributes used by the asp.net page parser and compiler and
can be included only in .ascx files (user controls).
@ implements The @implements directive gets the asp.net pages to implement .net
framework interfaces. This directive only supports a single attribute interface.
@ master Identifies a page as a master page and defines attributes used by the asp.net page
parser and compiler and can be included only in .master files.
@ page The @page directive enables you to specify attributes and values for an asp.net page
to be used when the page is parsed and compiled. Every .aspx files should include this @page
directive to execute. There are many attributes belong to this directive.
@ reference Links a page, user control, or com control to the current page or user control
declaratively.
@ register Associates aliases with namespaces and classes, which allow user controls and
custom server controls to be rendered when included in a requested page or user control.

csresources.in/aspnotes/aspnet_unit1.htm 8/16
4/23/22, 1:05 PM ASP.NET UNIT-1

CODE DECLARATION BLOCKS A code declaration block contains all the application logic for
your ASP.NET page and all the global variable declarations, subroutines, and functions. It must
appear within a <Script Runat="Server"> tag.
Codefile specifies a path to the referenced code-behind file for the page. Inherits defines the name of
the class from which to inherit. This can be any class derived from the page class

1.11 Page Life Cycle Events


Page_Init This is fired when the page is initialized
Page_Load This is fired when the page is loaded.
The difference between Page_Init and Page_load is that the controls are guaranteed to be
fully loaded in the Page_load.The controls are accessible in the Page_Init event,but the
ViewState is not loaded,so controls will have their default values,rather than any values
set during the postback.
Control_Event This is fired if a control triggered the page to be reloaded (such as a button)
Page_unload This is fired when the page is unloaded from the memory

1.12. TYPES OF CONTROLS IN ASP.NET


1.12.1 HTML Server Controls
HTML elements in ASP.NET files are, by default, treated as text. To make these elements
programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the
element should be treated as a server control.
Note: All HTML server controls must be within a <form> tag with the runat="server" attribute!,
ASP.NET requires that all HTML elements must be properly closed and properly nested.

SYNTAX
<INPUT TYPE=TEXT RUNAT=SERVER>

HTML Server Description


Control
HtmlAnchor Controls an <a> HTML tag
HtmlButton Controls a <button> HTML tag
HtmlForm Controls a <form> HTML tag
HtmlImage Controls an <image> HTML tag
HtmlInputButton Controls <input type="button">, <input
type="submit">, and <input type="reset">
HTML tags
HtmlInputCheckBox Controls an <input type="checkbox"> HTML
tag
HtmlInputFile Controls an <input type="file"> HTML tag
HtmlInputHidden Controls an <input type="hidden"> HTML tag
HtmlInputImage Controls an <input type="image"> HTML tag
HtmlInputRadioButton Controls an <input type="radio"> HTML tag

csresources.in/aspnotes/aspnet_unit1.htm 9/16
4/23/22, 1:05 PM ASP.NET UNIT-1

HtmlInputText Controls <input type="text"> and <input


type="password"> HTML tags
HtmlSelect Controls a <select> HTML tag
HtmlTable Controls a <table> HTML tag
HtmlTableCell Controls <td>and <th> HTML tags
HtmlTableRow Controls a <tr> HTML tag
HtmlTextArea Controls a <textarea> HTML tag
1.12.2 WEBSERVER CONTROLS
Web server controls are special ASP.NET tags understood by the server. Like HTML server
controls, Web server controls are also created on the server and they require a runat="server"
attribute to work.

Standard Controls List Controls Validation Controls Data bound Misc Controls
Controls
§ label § Radio Button 1. Required field § Data Grid § Crystal
§ Textbox List Validator § Data List Report
§ Button § Check Box List 2. Range Validator § Repeater Viewer
§ Link Button § Dropdown List control
§ Image Button § List Box 3. Compare Validator
§ Calendar 4. Regular Expression
§ AdRotator Validator
§ Panel
§ Place Holder 5. Custom Validator
§ Table 6. Validation
§ Literal Control Summary
§ Radio Button
§ Check Box
§ XML

Common Syntax for any web server control


<asp:controltype id=“name of the control” runat=“server”
----------------
----------------
//additional properties
></asp:controltype>

In order to set or get the value from any standard control text property should be used.
Eg: <asp:label id=“lb1” runat=“server” text=“user name”></asp:label>
<asp:button id=“lb1” runat=“server” text=“Login” />

Web Server Description


Control
AdRotator Displays a sequence of images
Button Displays a push button
Calendar Displays a calendar
CheckBox Displays a check box

csresources.in/aspnotes/aspnet_unit1.htm 10/16
4/23/22, 1:05 PM ASP.NET UNIT-1

CheckBoxList Creates a multi-selection check box


group
DataGrid Displays fields of a data source in a
grid
DataList Displays items from a data source by
using templates
DropDownList Creates a drop-down list
HyperLink Creates a hyperlink
Image Displays an image
ImageButton Displays a clickable image
Label Displays static content which is
programmable
LinkButton Creates a hyperlink button
ListBox Creates a single- or multi-selection
drop-down list
ListItem Creates an item in a list
Literal Displays static content which is
programmable
Panel Provides a container for other
controls
PlaceHolder Reserves space for controls added by
code
RadioButton Creates a radio button
RadioButtonList Creates a group of radio buttons
BulletedList Creates a list in bullet format
Repeater Displays a repeated list of items
bound to the control
Style Sets the style of controls
Table Creates a table
TableCell Creates a table cell
TableRow Creates a table row
TextBox Creates a text box

1.12.3 TEXTBOX
TextBox is a server side control. It is an input control which is used to take user input.

The asp tag to create TextBox is:


< asp:TextBoxID="TextBox1" runat="server" ></asp:TextBox>

Notable Properties of TextBox are :


AccessKey : It is used to set keyboard shortcut for the control.
TabIndex : The tab order of the control.
BackColor : It is used to set background color of the control.
BorderColor : It is used to set border color of the control.

csresources.in/aspnotes/aspnet_unit1.htm 11/16
4/23/22, 1:05 PM ASP.NET UNIT-1

BorderWidth : It is used to set width of border of the control.


Font : It is used to set font for the control text.
Text : It is used to set text to be shown for the control.
ToolTip : It displays the text when mouse is over the control.
Visible : To set visibility of control on the form.
Height : It is used to set height of the control.
Width : It is used to set width of the control.
MaxLength : It is used to set maximum number of characters that can be entered.

1.12.4 BUTTON
Buttons control is a server side control and is used to perform events. It is used to submit client
request to the server.
The asp tag to create Button is:
< asp:ButtonID="Button1" runat="server" Text="Submit" BorderStyle="Solid"
ToolTip="Submit"/>

Notable Properties of Button are :


AccessKey : It is used to set keyboard shortcut for the control.
TabIndex : The tab order of the control.
BackColor : It is used to set background color of the control.
BorderColor : It is used to set border color of the control.
BorderWidth : It is used to set width of border of the control.
Font : It is used to set font for the control text.
ForeColor : It is used to set color of the control text.
Text : It is used to set text to be shown for the control.
ToolTip : It displays the text when mouse is over the control.
Visible : To set visibility of control on the form.
Height : It is used to set height of the control.
Width : It is used to set width of the control.

1.12.5 LABEL
Label control is used to display textual information on the web forms. It is mainly used to create
caption for the other controls like textbox.

The asp tag to create Label is:


< asp:LabelID="Label1" runat="server" Text="Label" ></asp:Label>

Notable Properties of Label are :


AccessKey : It is used to set keyboard shortcut for the label.
TabIndex : The tab order of the control.
BackColor : It is used to set background color of the label.
BorderColor : It is used to set border color of the label.
BorderWidth : It is used to set width of border of the label.
Font : It is used to set font for the label text.
ForeColor : It is used to set color of the label text.
Text : It is used to set text to be shown for the label.
ToolTip : It displays the text when mouse is over the label.

csresources.in/aspnotes/aspnet_unit1.htm 12/16
4/23/22, 1:05 PM ASP.NET UNIT-1

Visible : To set visibility of control on the form.


Height : It is used to set height of the control.
Width : It is used to set width of the control.

1.12.6 RadioButtonList The RadioButtonList Web server control is used to display a list of
radio buttons. This control provides with a single-selection radio button group that can be
dynamically generated via data binding. The Items property of this control allows us to add items to
the control. To determine which item is selected, the SelectedItem property of the list is used.
RadioButtonList event : The default event of the RadioButtonList is the
SelectedIndexChanged which looks like this in code:
Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As
System.Object,_ByVal e As System.EventArgs) Handles
RadioButtonList1.SelectedIndexChanged
End Sub

Notable properties of the RadioButtonList control are as follows:


Items : Gets/Sets the collection of items in the list
RepeatColumns : Gets/Sets the number of displayed columns in the radio button list
RepeatDirection : Gets/Sets the display direction of radio buttons
RepeatLayout : Gets/Sets the radio button layout
TextAlign : Gets/Sets the radio button's text alignment

RadioButtonListSample
The following code will displayed after adding some items to the radio button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
TextBox1.Text = RadioButtonList1.SelectedItem.Text
End Sub

5. CheckBoxList The CheckBoxList Web server control displays a number of checkboxes at


once. This control provides a multi selection check box group that can be dynamically generated
with data binding. It contains an Items collection with members that correspond to individual items
in the list. To determine which items are checked, we need to test the Selected property of each item
in the list.

Notable properties of the CheckBoxList control are as follows:


Items : Gets/Sets the collection of items in the list
RepeatColumns : Gets/Sets the number of displayed columns in the check
box list
RepeatDirection : Gets/Sets the display direction of checkboxes
RepeatLayout : Gets/Sets the checkbox layout
TextAlign : Gets/Sets the check box's text alignment

CheckBoxList Sample
Drag a CheckBoxList, TextBox and a Button on to the form. Select the CheckBoxList and
add some items to it using the Items property. The following code will display the text of the

csresources.in/aspnotes/aspnet_unit1.htm 13/16
4/23/22, 1:05 PM ASP.NET UNIT-1

checkbox that is checked in the textbox when the button is clicked.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
TextBox1.Text = CheckboxList1.SelectedItem.Text
End Sub

1.13 SAMPLE ASP.NET PROGRAM (Using TextBox, RadioButton, Button):

Aim : To choose sex of a candidate from radiobutton, Read age of the candidate from a textbox and
determine, whether the candidate is eligible for marriage.

<%@ Page Language="VB" CodeFile="Default.aspx.vb" %>


<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Style="left: 296px; position: absolute; top:
80px" Width="24px"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Style="left: 160px; position: absolute; top:
216px" Width="216px"> </asp:TextBox>
<asp:Label ID="Label1" runat="server" Style= "left: 264px; position: absolute; top: 80px"
Text="Age"> </asp:Label>
<asp:Label ID="Label2" runat="server" Style= "left: 8px; position: absolute; top: 80px"
Text="Sex"> </asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" Style="left: 0px; position: absolute;
top: 112px" Text="Male" />
<asp:RadioButton ID="RadioButton2" runat="server" Style="left: 0px; position: absolute;
top: 144px" Text="Female" />
<asp:Button ID="Button1" runat="server" Style="left: 88px; position: absolute;top: 216px"
Text="CHECK" />
</div>
</form>
</body>
</html>

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Button1.Click
If RadioButton1.Checked = True And Val(TextBox1.Text) > 24 Then
TextBox2.Text = "ELIGIBLE FOR MARRIAGE"
Else
TextBox2.Text = "NOT ELIGIBLE FOR MARRIAGE"
End If
If RadioButton2.Checked = True And Val(TextBox1.Text) > 21 Then
TextBox2.Text = "ELIGIBLE FOR MARRIAGE"
Else
TextBox2.Text = "NOT ELIGIBLE FOR MARRIAGE"
End If

csresources.in/aspnotes/aspnet_unit1.htm 14/16
4/23/22, 1:05 PM ASP.NET UNIT-1

RadioButton1.Checked = False
RadioButton2.Checked = False
End Sub

csresources.in/aspnotes/aspnet_unit1.htm 15/16
4/23/22, 1:05 PM ASP.NET UNIT-1

csresources.in/aspnotes/aspnet_unit1.htm 16/16

You might also like