Unit 1
Unit 1
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.
csresources.in/aspnotes/aspnet_unit1.htm 1/16
4/23/22, 1:05 PM ASP.NET UNIT-1
csresources.in/aspnotes/aspnet_unit1.htm 2/16
4/23/22, 1:05 PM ASP.NET UNIT-1
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.
csresources.in/aspnotes/aspnet_unit1.htm 4/16
4/23/22, 1:05 PM ASP.NET UNIT-1
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.
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( "[email protected]", "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
SYNTAX
<INPUT TYPE=TEXT RUNAT=SERVER>
csresources.in/aspnotes/aspnet_unit1.htm 9/16
4/23/22, 1:05 PM ASP.NET UNIT-1
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
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” />
csresources.in/aspnotes/aspnet_unit1.htm 10/16
4/23/22, 1:05 PM ASP.NET UNIT-1
1.12.3 TEXTBOX
TextBox is a server side control. It is an input control which is used to take user input.
csresources.in/aspnotes/aspnet_unit1.htm 11/16
4/23/22, 1:05 PM ASP.NET UNIT-1
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"/>
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.
csresources.in/aspnotes/aspnet_unit1.htm 12/16
4/23/22, 1:05 PM ASP.NET UNIT-1
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
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
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
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.
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