C# -ASP.NET
C# -ASP.NET
5
web application, creating a sample ASP.NET 4.5 website,
application structure and state, global.asax application file, web
forms – standard controls, validation controls, master pages, web
services.
INTRODUCTION TO ASP.NET:
Overview:
- Asp.net is one of the most powerful web application development
platforms.
- It is becoming more useful & popular with the release of upgraded
versions.
- Asp.net 4.5 includes several enhancements in ASP.NET core, run
time & framework and ASP.NET web forms & contain a new version
of MVC(Model, View, Controller) named ASP.NET MVC4.
- The new Javascript, HTML & CSS editors are also integrated with
visual studio 2012 to simplify the web appln development.
- Asp.net provides services to allow the creation, development &
execution of web appln & web services.
- Asp.net is a server side technology.
- Web aplns are built using web forms, Asp.net comes with built-in
web forms controls, which are responsible for generating the user
- Web forms are designed to make building web-based applications
easy.
● Intrinsic controls:
- Are HTML elements that gather user info. They are specified in ASP
namespace. They can create intelligent controls that automatically
maintain standard & provide extra features.
<asp: Button> <asp: Label> <asp: Image> <asp: Hyper
Link>
<asp: Text Box> <asp: Table> <asp: Radio Button> <asp:
List Box> <asp: Table Row>
● Diff categories of web server controls:
1. Standard controls(Intrinsic – link HTML)
Ex: Label, Text box, Check box.......
2. Data controls
Ex: grid view, data list, repeater....
3. Navigation controls
Ex: tree view, menu.....
- Syntax:
<asp: control name id= “ ” runat= “server”...>
</asp: control name>
● Web form is providing 3 views
1. Design view: this will display preview of web page output &
supports arrangement of controls using drag & drop.
2. Source view” this will display markup content (tags) of web page –
allows creating controls manually.
3. Logic view” allows developer to write logic part of web page.
❖ Using states:
- by using in a web appln, u can preserve the state of appln either at server/
client end. The string of web appln helps u to store runtime changes that have
been made to web appln.
❖ Validation controls
- Are the controls used for validating the data entered in an input
control ∍ Text Box.
- When a user enters data on a web page & submits the page to the
server, validation controls are invoked to check the data entered by
user.
- If any of the data is invalid the validation control displays an error
message on the screen.
- The error message is defined as a property value of validation
control.
- Ensuring proper input from user is called validation.
- Ex: user name cannot be blank
Mobile number requests 10 digit nos.
- Validation controls can be used to validate user input at client side/
server side, default is client side validation controls will provide
built- in code to perform diff types of validations, this makes
developer job easier & faster in web site development – save time
& enhances efficiency.
- (from asp.net 3.0 onwards validation controls script is not visible to
developer)
● Validation controls
1. Required Field Validator control.
2. Range Validator control.
3. Compare Validator control.
4. Regular Expression Validator control.
5. Custom validator control.
6. Validation summary control.
● Comman properties of validation controls:
1. Control to Validate: specify std control id to validate user inpute.
2. Text: specify error message to be displayed if user provides an
invalid input.
3. Error message: specify error message to be displayed with
validation summary control.
4. Enable client script – true/ false
True [default] – client side validation
False - server side validation
● Base Validator class:
System. Web. UI. Web controls. Base Validator class provides basic
impl required for all validation controls.
1. Required Field Validator:
- Simplest controls – used to ensure that
the user has entered data into input
control.
- Can be used for mandatory fields.
- Ex: go to a website.
Add web form (default2 .aspx)
Add table, add 2 labels, 2 text boxer Required Field Validator
NOTE:
2. One validation control can validate only one text box, it can not
validate more than one text box.
3. Text box applied with more than one validation control requires
setting display property.
2. Nested Master page: implies that a master page can be included
inside another master page. The master page which contain
another master page inside it, is known as parent master page, &
the master page that is placed inside parent master page is known
as child\sub master page
- Is similar to simple master page should be used when you want to
crate a hierarchy of templates for website.
- Create parent master page as,
<% @ master language= ”c# ” Auto event wireup=“true code
file=”parent.master.cs” Inherits= “parent/”%>
- Create child master page as
<%@master language =”c#” master page file =”~/parent.master
Auto event wire up=”true” code file =” child.master.cs” Inherits
=”child” %>
- Ex: website with 3 departments: HR, Marketing, finance. Main
page consist of Header with logo & footer when emp accesses the
site, home page appears. In home page, the emp need to login to
access their department. ∴ u need to design diff interfaces for
every depts.. (which also include header & footer displayed on
main page)
- Define parent master page & design its struct & create 3 child
master pages to lay down diff interfaces for each dept. Every child
inherits the struct of parent & also uses Content Place Holder
control to define its own content. Content page of child maps with
parent master page & makes a nested master page.
- Nested master page is combination of parent master page, a child
master page and a content page.
- Advantage of this technique is whenever u want to change
company logo\header, modify only parent master page & then all
web pages would reflect those changes.