SlideShare a Scribd company logo
ASP .NET
Web Form Fundamentals



     For Beginners
       http://www.rajpatsystems.com
ASP.NET Application
An ASP.NET application is a combination of files,
  pages, handlers, modules, and executable
  code that can be invoked from a virtual
  directory (and, optionally, its subdirectories)
  on a web server. In other words, the virtual
  directory is the basic grouping structure that
  delimits an application.



                  http://www.rajpatsystems.com
http://www.rajpatsystems.com
ASP.NET File Types




 http://www.rajpatsystems.com
ASP.NET Application Directories




           http://www.rajpatsystems.com
Server Controls
• Server controls are created and configured as
  objects. They run on the web server and they
  automatically provide their own HTML output.
• Server controls behave like their Windows
  counterparts by maintaining state and raising
  events that you can react to in code.
• ASP.NET actually provides two sets of server-
  side controls that you can incorporate into
  your web forms.

                 http://www.rajpatsystems.com
HTML server controls & Web controls
• HTML server controls: These are server-based equivalents
  for standard HTML elements.
   – These controls are ideal if you’re a seasoned web programmer
     who prefers to work with familiar HTML tags (at least at first).
   – They are also useful when migrating ordinary HTML pages or
     ASP pages to ASP.NET, because they require the fewest changes.
• Web controls: These are similar to the HTML server
  controls, but they provide a richer object model with a
  variety of properties for style and formatting details.
   – They also provide more events and more closely resemble the
     controls used for Windows development.
   – Web controls also feature some user interface elements that
     have no direct HTML equivalent, such as the GridView, Calendar,
     and validation controls.

                         http://www.rajpatsystems.com
HTML Server Controls
•   HTML server controls provide an object interface for standard HTML elements.
    They provide three key features:
•   They generate their own interface: You set properties in code, and the underlying
    HTML tag is created automatically when the page is rendered and sent to the
    client.
•   They retain their state: Because the Web is stateless, ordinary web pages need to
    do a lot of work to store information between requests.
     – HTML server controls handle this task automatically. For example, if the user selects an item in
       a list box, that item remains selected the next time the page is generated.
     – Or, if your code changes the text in a button, the new text sticks the next time the page is
       posted back to the web server.
•   They fire server-side events: For example, buttons fire an event when clicked, text
    boxes fire an event when the text they contain is modified, and so on.
     – Your code can respond to these events, just like ordinary controls in a Windows application. In
       ASP code, everything is grouped into one block that executes from start to finish.
     – With event-based programming, you can easily respond to individual user actions and create
       more structured code.
     – If a given event doesn’t occur, the event-handler code won’t be executed.




                                      http://www.rajpatsystems.com
The HTML Control Classes




      http://www.rajpatsystems.com
http://www.rajpatsystems.com
http://www.rajpatsystems.com
Important HTML Control Properties




            http://www.rajpatsystems.com
http://www.rajpatsystems.com
How ASP .NET Application Works
•   First, the request for the page is sent to the web server. If you’re running a
    live site, the web server is almost certainly IIS. If you’re running the page
    in Visual Studio, the request is sent to the built-in test server.
•   The web server determines that the .aspx file extension is registered with
    ASP.NET and passes it to the ASP.NET worker process. If the file extension
    belonged to another service (as it would for .asp or .html files), ASP.NET
    would never get involved.
•   If this is the first time a page in this application has been requested,
    ASP.NET automatically creates the application domain. It also compiles all
    the web page code for optimum performance, and caches the compiled
    files in the directory c:Windows
    Microsoft.NETFrameworkv2.0.50727Temporary ASP.NET Files. If this ask
    has already been performed, ASP.NET will reuse the compiled version of
    the page.
•   The compiled aspx page acts like a miniature program. It starts firing
    events (most notably, the Page.Load event). However, you haven’t created
    an event handler for that event, so no code runs. At this stage, everything
    is working together as a set of in-memory .NET objects.
•   When the code is finished, ASP.NET asks every control in the web page to
    render itself into the corresponding HTML markup.
•   The final page is sent to the user, and the application ends.
                               http://www.rajpatsystems.com
http://www.rajpatsystems.com
The HtmlControl Base Class
• Every HTML control inherits from the base
  class HtmlControl. This relationship means
  that every HTML control will support a basic
  set of properties and features.




                  http://www.rajpatsystems.com
http://www.rajpatsystems.com
http://www.rajpatsystems.com
The HtmlContainerControl Class
•   Any HTML control that requires a closing tag inherits from the HtmlContainer class
    (which in turn inherits from the more basic HtmlControl class). For example,
    elements such as <a>, <form>, and <div> always use a closing tag, because they
    can contain other HTML elements.

•   On the other hand, elements such as <img> and <input> are used only as stand-
    alone tags. Thus, the HtmlAnchor, HtmlForm, and HtmlGenericControl classes
    inherit from

•   HtmlContainerControl, while HtmlInputImage and HtmlInputButton do not. The
    HtmlContainer control adds two properties to those defined in HtmlControl.




                                                                  http://www.rajpatsystems.com
The HtmlInputControl Class
•   This control defines some properties that are used for the <input>
    element. As you’ve already learned, the <input> element can represent
    different controls, depending on the type attribute. The <input
    type="text"> element is a text box and <input type="submit"> is a button.




                              http://www.rajpatsystems.com
The Page Class
• Every web page is a custom class that inherits
  from System.Web.UI.Page.
• By inheriting from this class, your web page
  class acquires a number of properties and
  methods that your code can use.
• These include properties for enabling caching,
  validation, and tracing


                  http://www.rajpatsystems.com
http://www.rajpatsystems.com
Sending the User to a New Page
• Click <a href="newpage.aspx">here</a> to go to
  newpage.aspx.
• HttpResponse.Redirect()
   – you can get access to the current HttpResponse object
     through the Page.Response property.
   – Response.Redirect("newpage.aspx");
   – Response.Redirect("http://www.prosetech.com");
• HttpServerUtility.Transfer()
   – An HttpServerUtility object is provided through the
     Page.Server property
   – Server.Transfer("newpage.aspx");

                      http://www.rajpatsystems.com
HTML Encoding




  http://www.rajpatsystems.com
Application Events




    http://www.rajpatsystems.com
The Global.asax File
• To add a Global.asax file to an application in
   Visual Studio, choose Website –> Add New
 Item, and select the Global Application Class file
   type. Then, click OK.




                   http://www.rajpatsystems.com
ASP.NET Configuration
• Every web application includes a web.config file that configures
  fundamental settings everything from the way error messages are
  shown to the security settings that lock out unwanted visitors.
• The ASP.NET configuration files have several key advantages:
   – They are never locked: You can update web.config settings at any
     point, even while your application is running. If there are any requests
     currently under way, they’ll continue to use the old settings, while
     new requests will get the changed settings right away.
   – They are easily accessed and replicated: Provided you have the
     appropriate network rights, you can change a web.config file from a
     remote computer. You can also copy the web.config file and use it to
     apply identical settings to another application or another web server
     that runs the same application in a web farm scenario.
   – The settings are easy to edit and understand: The settings in the
     web.config file are humanreadable, which means they can be edited
     and understood without needing a special configuration tool.

                            http://www.rajpatsystems.com
The web.config File
• The web.config file uses a predefined XML format. The entire
  content of the file is nested in a root <configuration> element.
  Inside this element are several more subsections, some of which
  you’ll never change, and others which are more important.




                         http://www.rajpatsystems.com
Nested Configuration
• ASP.NET uses a multilayered configuration system that allows you to
  set settings at different levels.
   – Every web server starts with some basic settings that are defined in
     two configuration files in the
     c:WindowsMicrosoft.NETFrameworkv2.0.50727Config directory.

   – These two files are machine.config and web.config. Generally, you
     won’t edit either of these files manually, because they affect the
     entire computer. Instead, you’ll configure the web.config file in your
     web application folder. Using that file, you can set additional settings
     or override the defaults that are configured in the two system files.

   – More interestingly, you can use different settings for different parts of
     your application. To use this technique, you need to create additional
     subdirectories inside your virtual directory. These subdirectories can
     contain their own web.config files with additional settings.

                             http://www.rajpatsystems.com
http://www.rajpatsystems.com
Storing Custom Settings in the
                web.config File
•   ASP.NET also allows you to store your own settings in the web.config file,
    in an element called <appSettings>. Note that the <appSettings> element
    is nested in the root <configuration> element.




                              http://www.rajpatsystems.com
The custom settings that you add are written as simple string
  variables. You might want to use a special web.config
  setting for several reasons:
   – To centralize an important setting that needs to be used in
     many different pages: For example, you could create a variable
     that stores a database query. Any page that needs to use this
     query can then retrieve this value and use it.
   – To make it easy to quickly switch between different modes of
     operation: For example, you might create a special debugging
     variable. Your web pages could check for this variable and, if it’s
     set to a specified value, output additional information to help
     you test the application.
   – To set some initial values: Depending on the operation, the user
     might be able to modify these values, but the web.config file
     could supply the defaults.

• You can enter custom settings using an <add> element that
  identifies a unique variable name (key) and the variable
  contents (value).    http://www.rajpatsystems.com
http://www.rajpatsystems.com
http://www.rajpatsystems.com
Ad

More Related Content

What's hot (20)

Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
Madhuri Kavade
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
Naveen Sihag
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
Deep Patel
 
Event handling
Event handlingEvent handling
Event handling
Shree M.L.Kakadiya MCA mahila college, Amreli
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
Asp net
Asp netAsp net
Asp net
Dr. C.V. Suresh Babu
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
Surbhi Panhalkar
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
Rishi Kothari
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
Bhumivaghasiya
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
Venkateswara Rao N
 
android activity
android activityandroid activity
android activity
Deepa Rani
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
VMahesh5
 
Android intents
Android intentsAndroid intents
Android intents
Siva Ramakrishna kv
 

Viewers also liked (20)

.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl....net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
Nancy Thomas
 
Hanover Seminars
Hanover SeminarsHanover Seminars
Hanover Seminars
Seven Questions Consulting Limited
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
246paa
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
Bhushan Mulmule
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
Bhushan Mulmule
 
OOP with C#
OOP with C#OOP with C#
OOP with C#
Manuel Scapolan
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
veera
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Concepts of Asp.Net
Concepts of Asp.NetConcepts of Asp.Net
Concepts of Asp.Net
vidyamittal
 
Tootimes
TootimesTootimes
Tootimes
Looppa
 
The Future in designing for the sex(es)
The Future in designing for the sex(es)The Future in designing for the sex(es)
The Future in designing for the sex(es)
Cathy Wang
 
เสนอค่าย
เสนอค่ายเสนอค่าย
เสนอค่าย
Montira Hokjaroen
 
Learning with Quest Atlantis in Singapore
Learning with Quest Atlantis in SingaporeLearning with Quest Atlantis in Singapore
Learning with Quest Atlantis in Singapore
mediaplaylab
 
Looppa case study (Guarida)
Looppa case study (Guarida)Looppa case study (Guarida)
Looppa case study (Guarida)
Looppa
 
WTI - Storytelling and Social Media for Business Owners - B Gemmell
WTI - Storytelling and Social Media for Business Owners - B GemmellWTI - Storytelling and Social Media for Business Owners - B Gemmell
WTI - Storytelling and Social Media for Business Owners - B Gemmell
South Scotland Innovation Network
 
Teaching disgrace using Second Life
Teaching disgrace using Second LifeTeaching disgrace using Second Life
Teaching disgrace using Second Life
mediaplaylab
 
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl....net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
Nancy Thomas
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
246paa
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
Bhushan Mulmule
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
Bhushan Mulmule
 
c#.Net Windows application
c#.Net Windows application c#.Net Windows application
c#.Net Windows application
veera
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Concepts of Asp.Net
Concepts of Asp.NetConcepts of Asp.Net
Concepts of Asp.Net
vidyamittal
 
Tootimes
TootimesTootimes
Tootimes
Looppa
 
The Future in designing for the sex(es)
The Future in designing for the sex(es)The Future in designing for the sex(es)
The Future in designing for the sex(es)
Cathy Wang
 
Learning with Quest Atlantis in Singapore
Learning with Quest Atlantis in SingaporeLearning with Quest Atlantis in Singapore
Learning with Quest Atlantis in Singapore
mediaplaylab
 
Looppa case study (Guarida)
Looppa case study (Guarida)Looppa case study (Guarida)
Looppa case study (Guarida)
Looppa
 
WTI - Storytelling and Social Media for Business Owners - B Gemmell
WTI - Storytelling and Social Media for Business Owners - B GemmellWTI - Storytelling and Social Media for Business Owners - B Gemmell
WTI - Storytelling and Social Media for Business Owners - B Gemmell
South Scotland Innovation Network
 
Teaching disgrace using Second Life
Teaching disgrace using Second LifeTeaching disgrace using Second Life
Teaching disgrace using Second Life
mediaplaylab
 
Ad

Similar to Asp .net web form fundamentals (20)

Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
Lecture slides_Introduction to ASP.NET presentation
Lecture slides_Introduction to ASP.NET presentationLecture slides_Introduction to ASP.NET presentation
Lecture slides_Introduction to ASP.NET presentation
ssuserbf6ebe
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
Neeraj Mathur
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
application developer
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
Akhil Mittal
 
Web tech
Web techWeb tech
Web tech
SangeethaSasi1
 
Web tech
Web techWeb tech
Web tech
SangeethaSasi1
 
Web techh
Web techhWeb techh
Web techh
SangeethaSasi1
 
Web tech
Web techWeb tech
Web tech
SangeethaSasi1
 
Asp introduction
Asp introductionAsp introduction
Asp introduction
Sireesh K
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architecture
Iblesoft
 
Parallelminds.asp.net with sp
Parallelminds.asp.net with spParallelminds.asp.net with sp
Parallelminds.asp.net with sp
parallelminder
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
Julie Iskander
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
Raed Aldahdooh
 
Ch 04 asp.net application
Ch 04 asp.net application Ch 04 asp.net application
Ch 04 asp.net application
Madhuri Kavade
 
Programming web application
Programming web applicationProgramming web application
Programming web application
aspnet123
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
Prashant Kumar
 
Introduction to asp
Introduction to aspIntroduction to asp
Introduction to asp
Madhuri Kavade
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
aspnet123
 
Asp.Net 3 5 Part 1
Asp.Net 3 5 Part 1Asp.Net 3 5 Part 1
Asp.Net 3 5 Part 1
asim78
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
Lecture slides_Introduction to ASP.NET presentation
Lecture slides_Introduction to ASP.NET presentationLecture slides_Introduction to ASP.NET presentation
Lecture slides_Introduction to ASP.NET presentation
ssuserbf6ebe
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
Neeraj Mathur
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
Akhil Mittal
 
Asp introduction
Asp introductionAsp introduction
Asp introduction
Sireesh K
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architecture
Iblesoft
 
Parallelminds.asp.net with sp
Parallelminds.asp.net with spParallelminds.asp.net with sp
Parallelminds.asp.net with sp
parallelminder
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
Raed Aldahdooh
 
Ch 04 asp.net application
Ch 04 asp.net application Ch 04 asp.net application
Ch 04 asp.net application
Madhuri Kavade
 
Programming web application
Programming web applicationProgramming web application
Programming web application
aspnet123
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
Prashant Kumar
 
Introducing asp
Introducing aspIntroducing asp
Introducing asp
aspnet123
 
Asp.Net 3 5 Part 1
Asp.Net 3 5 Part 1Asp.Net 3 5 Part 1
Asp.Net 3 5 Part 1
asim78
 
Ad

Asp .net web form fundamentals

  • 1. ASP .NET Web Form Fundamentals For Beginners http://www.rajpatsystems.com
  • 2. ASP.NET Application An ASP.NET application is a combination of files, pages, handlers, modules, and executable code that can be invoked from a virtual directory (and, optionally, its subdirectories) on a web server. In other words, the virtual directory is the basic grouping structure that delimits an application. http://www.rajpatsystems.com
  • 4. ASP.NET File Types http://www.rajpatsystems.com
  • 5. ASP.NET Application Directories http://www.rajpatsystems.com
  • 6. Server Controls • Server controls are created and configured as objects. They run on the web server and they automatically provide their own HTML output. • Server controls behave like their Windows counterparts by maintaining state and raising events that you can react to in code. • ASP.NET actually provides two sets of server- side controls that you can incorporate into your web forms. http://www.rajpatsystems.com
  • 7. HTML server controls & Web controls • HTML server controls: These are server-based equivalents for standard HTML elements. – These controls are ideal if you’re a seasoned web programmer who prefers to work with familiar HTML tags (at least at first). – They are also useful when migrating ordinary HTML pages or ASP pages to ASP.NET, because they require the fewest changes. • Web controls: These are similar to the HTML server controls, but they provide a richer object model with a variety of properties for style and formatting details. – They also provide more events and more closely resemble the controls used for Windows development. – Web controls also feature some user interface elements that have no direct HTML equivalent, such as the GridView, Calendar, and validation controls. http://www.rajpatsystems.com
  • 8. HTML Server Controls • HTML server controls provide an object interface for standard HTML elements. They provide three key features: • They generate their own interface: You set properties in code, and the underlying HTML tag is created automatically when the page is rendered and sent to the client. • They retain their state: Because the Web is stateless, ordinary web pages need to do a lot of work to store information between requests. – HTML server controls handle this task automatically. For example, if the user selects an item in a list box, that item remains selected the next time the page is generated. – Or, if your code changes the text in a button, the new text sticks the next time the page is posted back to the web server. • They fire server-side events: For example, buttons fire an event when clicked, text boxes fire an event when the text they contain is modified, and so on. – Your code can respond to these events, just like ordinary controls in a Windows application. In ASP code, everything is grouped into one block that executes from start to finish. – With event-based programming, you can easily respond to individual user actions and create more structured code. – If a given event doesn’t occur, the event-handler code won’t be executed. http://www.rajpatsystems.com
  • 9. The HTML Control Classes http://www.rajpatsystems.com
  • 12. Important HTML Control Properties http://www.rajpatsystems.com
  • 14. How ASP .NET Application Works • First, the request for the page is sent to the web server. If you’re running a live site, the web server is almost certainly IIS. If you’re running the page in Visual Studio, the request is sent to the built-in test server. • The web server determines that the .aspx file extension is registered with ASP.NET and passes it to the ASP.NET worker process. If the file extension belonged to another service (as it would for .asp or .html files), ASP.NET would never get involved. • If this is the first time a page in this application has been requested, ASP.NET automatically creates the application domain. It also compiles all the web page code for optimum performance, and caches the compiled files in the directory c:Windows Microsoft.NETFrameworkv2.0.50727Temporary ASP.NET Files. If this ask has already been performed, ASP.NET will reuse the compiled version of the page. • The compiled aspx page acts like a miniature program. It starts firing events (most notably, the Page.Load event). However, you haven’t created an event handler for that event, so no code runs. At this stage, everything is working together as a set of in-memory .NET objects. • When the code is finished, ASP.NET asks every control in the web page to render itself into the corresponding HTML markup. • The final page is sent to the user, and the application ends. http://www.rajpatsystems.com
  • 16. The HtmlControl Base Class • Every HTML control inherits from the base class HtmlControl. This relationship means that every HTML control will support a basic set of properties and features. http://www.rajpatsystems.com
  • 19. The HtmlContainerControl Class • Any HTML control that requires a closing tag inherits from the HtmlContainer class (which in turn inherits from the more basic HtmlControl class). For example, elements such as <a>, <form>, and <div> always use a closing tag, because they can contain other HTML elements. • On the other hand, elements such as <img> and <input> are used only as stand- alone tags. Thus, the HtmlAnchor, HtmlForm, and HtmlGenericControl classes inherit from • HtmlContainerControl, while HtmlInputImage and HtmlInputButton do not. The HtmlContainer control adds two properties to those defined in HtmlControl. http://www.rajpatsystems.com
  • 20. The HtmlInputControl Class • This control defines some properties that are used for the <input> element. As you’ve already learned, the <input> element can represent different controls, depending on the type attribute. The <input type="text"> element is a text box and <input type="submit"> is a button. http://www.rajpatsystems.com
  • 21. The Page Class • Every web page is a custom class that inherits from System.Web.UI.Page. • By inheriting from this class, your web page class acquires a number of properties and methods that your code can use. • These include properties for enabling caching, validation, and tracing http://www.rajpatsystems.com
  • 23. Sending the User to a New Page • Click <a href="newpage.aspx">here</a> to go to newpage.aspx. • HttpResponse.Redirect() – you can get access to the current HttpResponse object through the Page.Response property. – Response.Redirect("newpage.aspx"); – Response.Redirect("http://www.prosetech.com"); • HttpServerUtility.Transfer() – An HttpServerUtility object is provided through the Page.Server property – Server.Transfer("newpage.aspx"); http://www.rajpatsystems.com
  • 24. HTML Encoding http://www.rajpatsystems.com
  • 25. Application Events http://www.rajpatsystems.com
  • 26. The Global.asax File • To add a Global.asax file to an application in Visual Studio, choose Website –> Add New Item, and select the Global Application Class file type. Then, click OK. http://www.rajpatsystems.com
  • 27. ASP.NET Configuration • Every web application includes a web.config file that configures fundamental settings everything from the way error messages are shown to the security settings that lock out unwanted visitors. • The ASP.NET configuration files have several key advantages: – They are never locked: You can update web.config settings at any point, even while your application is running. If there are any requests currently under way, they’ll continue to use the old settings, while new requests will get the changed settings right away. – They are easily accessed and replicated: Provided you have the appropriate network rights, you can change a web.config file from a remote computer. You can also copy the web.config file and use it to apply identical settings to another application or another web server that runs the same application in a web farm scenario. – The settings are easy to edit and understand: The settings in the web.config file are humanreadable, which means they can be edited and understood without needing a special configuration tool. http://www.rajpatsystems.com
  • 28. The web.config File • The web.config file uses a predefined XML format. The entire content of the file is nested in a root <configuration> element. Inside this element are several more subsections, some of which you’ll never change, and others which are more important. http://www.rajpatsystems.com
  • 29. Nested Configuration • ASP.NET uses a multilayered configuration system that allows you to set settings at different levels. – Every web server starts with some basic settings that are defined in two configuration files in the c:WindowsMicrosoft.NETFrameworkv2.0.50727Config directory. – These two files are machine.config and web.config. Generally, you won’t edit either of these files manually, because they affect the entire computer. Instead, you’ll configure the web.config file in your web application folder. Using that file, you can set additional settings or override the defaults that are configured in the two system files. – More interestingly, you can use different settings for different parts of your application. To use this technique, you need to create additional subdirectories inside your virtual directory. These subdirectories can contain their own web.config files with additional settings. http://www.rajpatsystems.com
  • 31. Storing Custom Settings in the web.config File • ASP.NET also allows you to store your own settings in the web.config file, in an element called <appSettings>. Note that the <appSettings> element is nested in the root <configuration> element. http://www.rajpatsystems.com
  • 32. The custom settings that you add are written as simple string variables. You might want to use a special web.config setting for several reasons: – To centralize an important setting that needs to be used in many different pages: For example, you could create a variable that stores a database query. Any page that needs to use this query can then retrieve this value and use it. – To make it easy to quickly switch between different modes of operation: For example, you might create a special debugging variable. Your web pages could check for this variable and, if it’s set to a specified value, output additional information to help you test the application. – To set some initial values: Depending on the operation, the user might be able to modify these values, but the web.config file could supply the defaults. • You can enter custom settings using an <add> element that identifies a unique variable name (key) and the variable contents (value). http://www.rajpatsystems.com