Compiled By: Afaq Alam Khan
Compiled By: Afaq Alam Khan
{https://www.tutorialsteacher.com/core/
dotnet-core}
Journey of .Net Framework
Release History
Class Libraries
ASP.Net/ Web Forms
Language Support
ADO.Net
Application Execution
Assemblies[1]
[WebForms]
ASP.Net
ASP.NET is a technology for developing Web applications based on the Microsoft
.NET Framework.
It was first released in January 2002 with version 1.0 of the .NET Framework, and
is the successor to Microsoft's Active Server Pages (ASP) technology.
ASP.NET is built on the Common Language Runtime (CLR), allowing programmers to
write ASP.NET code using any supported .NET language, such as C# and VB.NET.
ASP.NET web pages or webpage, known officially as Web Forms, are the main
building block for application development. Web forms are contained in files with
an “.aspx” extension.
Like its predecessor (ASP), ASP.NET is server-side i.e., it runs on the Web server.
Instead of being interpreted by the client, server-side code is interpreted by the Web
server.
In the case of ASP.NET, the code in the page is read by the server and used
dynamically to generate standard HTML/JavaScript/CSS that is then sent to the
browser.
As all processing of ASP.NET code occurs on the server, it’s called a server-side
technology.
Programming Models
ASP.NET supports a number of programming models
for building web applications some of the popular
models are:
ASP.Net WebForms
ASP.Net MVC
ASP.NET lets you use your favorite programming language, or at least one that’s
really close to it. The .NET Framework currently supports over twenty languages, four
of which may be used to build ASP.NET Websites.
ASP.NET pages are compiled, not interpreted. Instead of reading and interpreting your
code every time a dynamic page is requested, ASP.NET compiles dynamic pages into
efficient binary files that the server can execute very quickly.
ASP.NET has full access to the functionality of the .NET Framework. Support for XML,
Web Services, database interaction, email, regular expressions, and many other
technologies are built right into .NET, which saves you from having to reinvent the
wheel.
ASP.NET allows you to separate the server-side code in your pages from the HTML
layout. When you’re working with a team composed of programmers and design
specialists, this separation is a great help, as it lets programmers modify the server-
side code without stepping on the designers’ carefully crafted HTML—and vice versa.
Execution of ASP.Net Files
ASP.Net page in
HTTP request for .aspx IIS Webserver .aspx resource Database
Server processing of
.aspx resource
.aspx resource
Result of .aspx
processing
.Net Framework
O.S
Compiling and Delivering ASP.NET Pages
The process of compiling and delivering ASP.NET pages goes through the
following stages:
1. IIS matches the URL in the request against a file on the physical file system (hard
disk) by translating the virtual path (for example,/site/ index.aspx) into a path relative
to the site’s Web root (for example, d:\domains\thisSite\wwwroot\site\index.aspx).
2. Once the file is found,the file extension (.aspx) is matched against a list of known file
types for either sending on to the visitor or for processing.
3. If this is first visit to the page since the file was last changed,the ASP code is
compiled into an assembly using the Common Language Runtime compiler, into MSIL,
and then into machine-specific binary code for execution.
4. The binary code is a .NET class .dll and is stored in a temporary location.
5. Next time the page is requested the server will check to see if the code has
changed. If the code is the same, then the compilation step is skipped and the
previously compiled class code is executed; otherwise,the class is deleted and
recompiled from the new source.
6. The compiled code is executed and the request values are
interpreted, such as form input fields or URL parameters.
7. If the developer has used Web forms, then the server can
detect what software the visitor is using and render pages that
are tailored to the visitors requirements, for example, returning
Netscape specific code, or Wireless Markup Language (WML)
code for mobiles.
ASP.NET pages are simply text files with the .aspx file name
extension that can be placed on an IIS server equipped with
ASP.NET.
When a browser requests an ASP.NET page, the ASP.NET runtime
parses and compiles the target file into a .NET Framework class.
An ASP.NET page consists of the following elements:
Directives
Code declaration blocks
Code render blocks
ASP.NET server controls
Server-side comments
Server-side include directives
Literal text and HTML tags
Client-side scripts
ASP.Net Page Structure
Directives
Page directives are used to set various attributes about a page. The ASP Engine and the compiler
follow these directives to prepare a page.
Directives start with the sequence <%@, followed by the directive name, plus any attributes
and their corresponding values, then end with %>.
There are many kinds of directives. The most frequently ones are the following: @Page,
@Import, @Implements, @ Register, @OutputCache and @Assembly directives. These
directives can be placed anywhere in a page, however, these are typically placed at the top.
ASP.Net Page Structure
Mycodefile.aspx
contains only
subroutines without
any script or html
tags
Code within a code declaration block is only executed when it is called or triggered by
user or page interactions.
ASP.Net Page Structure
• Server-Side Comments
<%--and --%>
• Server-Side Include Directives
Server-side include directives enable developers to insert the contents of an external file
anywhere within an ASP.NET page.
Controls are small building blocks of the graphical user interface, which
include text boxes, buttons, check boxes, list boxes, labels, and numerous
other tools. Using these tools, the users can enter data, make selections
and indicate their preferences.
Controls are also used for structural jobs, like validation, data access,
security, creating master pages, and data manipulation.
https://mycodelines.wordpress.com/2008/12/17/differences-between-html-server-controls-and-aspnet-server-controls/
ASP.Net Server Controls
ASP.NET server controls are the primary controls used in ASP.NET.
ASP.NET server controls with a visual aspect are derived from the
WebControl class and inherit all the properties, events, and methods
of this class.
The WebControl class itself and some other server controls that are
not visually rendered are derived from the System.Web.UI.Control
class.
ASP.Net server controls inherit all properties, events, and methods of
the WebControl and System.Web.UI.Control class.
For the full list of common properties and methods visit
https://www.tutorialspoint.com/asp.net/asp.net_server_controls.htm
ASP.Net Server Controls
Label
Standard Controls Button
Compare validator Checkbox
Validation Custom validator Checkboxlist
Range validator Dropdownlist
Data Regular expression validator Hyperlink
Required field
Navigation Validation summery
Image
Imagebutton
Login Listbox
Linkbutton
Webparts Gridview Imagebutton
Datalist Radiobutton
. Listview Radiobuttionlist
Repeater .
. Menu . .
SiteMapPath . .
TreeView
Standard Controls
TextBox
Botton
Hyperlink
Checkbox
Radiobutton
TextBox
Properties:
ID: specifies the identity of the control
Text: It is used to set text to be shown for the control.
Visible: To set visibility of control on the form. (True/False)
BorderColor: It is used to set border color of the control.
MaxLength:It is used to set maximum number of characters that can be entered.
ReadOnly:It is used to make control readonly. (True/False)
TextMode: SigleLine/Multiline/password/Date …..
AutoPostBack: If set to TRUE, will cause the page to postback if the text inside textbox is changed
EnableViewState: It is true by default. If set to false, textbox will not retain the contents after postback
.
.
.
Event: onTextChanged : will be invoked once the text inside the textbox is changed
Button
ASP.NET provides three types of button control:
Button : It displays text within a rectangular area.
Link Button : It displays text that looks like a hyperlink.
Image Button : It displays an image.
<asp:ListItem>Korea </asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
<asp:ListItem>Palestine</asp:ListItem>
<asp:ListItem>France</asp:ListItem>
</asp:DropDownList>
Properties:
Items: collection of items. DropDownList control can be populated at design time using items collection
Autopostback: if set to true, page will be posted back once the item is selected
EnableViewState: True by default. Retains the selected option after postback.
DataSource: DropDownList control can be bound to some datasource. This property is used to specify the
datasource
Datamember: Can be the name of table
DateTextField: Specified the name of field from the table. Data items in the selected column will appear as
options in the DropDownList control
DataValueField:
DropDownlist-Example
DropdownExample.aspx
.
.
Selected Country:<asp:Label ID="Label1"
runat="server" Text=""></asp:Label>
Code Behind
Country: <asp:DropDownList ID="DropDownList1"
runat="server"> DropdownExample.vb
<asp:ListItem>Korea </asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
Label1.Text =
<asp:ListItem>Palestine</asp:ListItem> DropDownList1.SelectedItem.ToString
<asp:ListItem>France</asp:ListItem>
</asp:DropDownList>
Codebehind
Dim strHobby As String = ""
For Each li As ListItem In CheckBoxList1.Items
If li.Selected Then
strHobby = strHobby + " " + li.Text
End If
Next
Label3.Text = strHobby
Exercise
Ex1: Consider a webform SelectCountry.aspx with code behind file
enabled. add two DropDownList controls (DDLC1, DDLC2) to the
SelectCountry.aspx. Populate the DDLC1 control with the list of
Countries (Australia, Bangladesh, India, Pakistan). Write a program
for the OnSelectedIndexChanged event of DDLC1 on codebehind
file which populates DDLC2 control with the name of the cities
depending upon the selected country in DDLC1.
IsValid: Has the value true when the validation check succeeds and false otherwise
Display: how the validator is rendered to your page (Static/ Dynamic/ None) {whether space for
displaying error message is reserved in advanced on the page or will be created on the Go}
Methods
Validate: Performs validation and updates IsValid Property
Example: write a custom validation function to make sure that the string in the
textbox contains “CUKmr”.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1"
ControlToValidate="TextBox1" ClientValidationFunction="myclientcustomfunction"
OnServerValidate="CustomValidator1_ServerValidate“
ValidateEmptyText="True“
Text =“Does not contain valid data”
runat="server"
</asp:CustomValidator>
Subroutine is implemented on code behind file and validation is done server side
Protected Sub CustomValidator1_ServerValidate(source As Object, args As ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
Dim str1 As String
str1 = args.Value
If str1.IndexOf("CUKmr") > -1 Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If IsValid Then
Label1.Text = "valid data"
Else
Label1.Text = "try again"
End If
myclientcustomfunction
Function is written in head section of .aspx file and validation is done on clientside
<script type="text/javascript">
function myclientcustomfunction(oSrc, args)
{
str1=args.Value
if (str1.indexOf("CUKmr") > -1)
args.IsValid = true;
else
args.IsValid = false;
}
</script>
Validation Summery
Displays a report of all validation errors occurred in a
Web page (All error messages togeather)
Properties
DisplayMode— Enables you to specify how the error
messages are formatted. Possible values are BulletList, List,
and SingleParagraph.
HeaderText— Enables you to display header text above the
validation summary.
ShowMessageBox— Enables you to display a popup alert
box (By Default False)
ShowSummary— Enables you to hide the validation summary
in the page (By default True)
Validation Summery - Example