SlideShare a Scribd company logo
Developing Web Applications Using ASP.NET
Objectives


                In this session, you will learn to:
                   Configure ViewState properties and ControlState properties for
                   Web server controls
                   Store and retrieve Application and Session state data
                   Implement out-of-process session state
                   Store and manage state data in the Cache object
                   Explain how to store and retrieve database connections by
                   using the Web.Config file
                   Explain how to use data source controls to access relational
                   data
                   Explain how to use data source controls to access XML data
                   Explain how to use data source controls to access object data




     Ver. 1.0                                                            Slide 1 of 26
Developing Web Applications Using ASP.NET
Demo: Managing State for a Web Application


                Problem Statement:
                   You are a developer in the Adventure Works organization, a
                   fictitious bicycle manufacturer. You have been asked to assist
                   in the development of the Business-to-Consumer (B2C) Web
                   application and a related Business-to-Employee (B2E) extranet
                   portal.
                   Decisions on the design of the application have already been
                   made. As part of the first phase of the B2C development, you
                   have been asked to configure the behavior of Web server
                   controls by manipulating their ViewState properties. You have
                   also been asked to add a site-counter to the site, which will
                   display user numbers and store data in the Application and
                   Session objects.




     Ver. 1.0                                                            Slide 2 of 26
Developing Web Applications Using ASP.NET
Demo: Managing State for a Web Application (Contd.)


                You will also specify how the Web application stores and
                manages session state data. Finally, you have been asked to
                implement caching by using the Cache object to store bike
                review data.




     Ver. 1.0                                                        Slide 3 of 26
Developing Web Applications Using ASP.NET
Demo: Managing State for a Web Application (Contd.)


                Solution:
                 • To solve this problem, you need to perform the following tasks:
                     1. Configuring ViewState Properties for Web Server Controls
                         a.   Open the Adventure Works Web site.
                         b.   Set the EnableViewState property of Web server controls.
                         c.   Test the ViewState after a Web page is submitted.
                         d.   Disable ViewState for the BikeReview.aspx page.
                         e.   Work with the MaxPageStateFieldLength property to divide the
                              ViewState data into chunks.
                     2. Storing and Retrieving Application and Session State
                         a. Initialize information in the Application object.
                         b. Write code to increment the UserCount value when a new user session
                            begins.
                         c. Store Data in the Session object.
                         d. Retrieve Application and Session state data and display it on the Web
                            page.




     Ver. 1.0                                                                           Slide 4 of 26
Developing Web Applications Using ASP.NET
Demo: Managing State for a Web Application (Contd.)


                1. Implementing Out-of-Process Session State
                    a.   Enable users to save their favorite trails in Session data.
                    b.   Configure IIS, and then test the application.
                    c.   Enable StateServer session management.
                    d.   Enable SQLServer session management.
                2. Storing and Managing State Data in the Cache Object
                    a.   Store data and retrieve data from the Cache object.
                    b.   Define dependencies between items in the Cache object.
                    c.   Delete invalid cached data.
                    d.   Implement Change Notifications in cached data to ensure that deleted
                         items are reloaded into the cache.




     Ver. 1.0                                                                          Slide 5 of 26
Developing Web Applications Using ASP.NET
Database Connections and the Web.Config File


                Database Connections and Connection Strings:
                   Web applications use database connections as the underlying
                   mechanism to perform various operations on the databases.
                   Database connections are defined in terms of a string that
                   specifies the properties of the connection.
                   Different databases support different properties and therefore
                   require different connection strings.




     Ver. 1.0                                                             Slide 6 of 26
Developing Web Applications Using ASP.NET
Database Connections and the Web.Config File (Contd.)


                Using the Web.config File to Simplify Connection String
                Management:
                   Connection strings can be hard coded into the Web application
                   pages.
                   This approach is difficult to manage because databases may
                   be moved, redefined, or upgraded.
                   This problem can be solved by using the Web.Config file to
                   store the connection strings.
                   This approach retrieves the details of connection strings at run
                   time from the Web.config file.




     Ver. 1.0                                                              Slide 7 of 26
Developing Web Applications Using ASP.NET
Database Connections and the Web.Config File (Contd.)


                This sample code shows part of a Web.Config file with a
                connection string:
                 <connectionStrings>
                      <add name="AdvWorks"
                          connectionString="Server=MySQLSever;

                          Database=AdventureWorks;
                          Integrated Security=SSPI;Persist Security
                          Info=True"
                          providerName="System.Data.SqlClient"/>
                 </connectionStrings>




     Ver. 1.0                                                         Slide 8 of 26
Developing Web Applications Using ASP.NET
Database Connections and the Web.Config File (Contd.)


                Retrieving Connection Strings at Run Time:
                   Connection string stored in the connectionStrings section
                   of the Web.Config file, can be retrieved at run time.
                   ConnectionStrings collection of
                   ConfigurationManager class is used to retrieve such
                   connection string.
                   This sample code shows how to retrieve connection strings at
                   run time and how to use them to open a database connection:
                    string myDataString =
                    ConfigurationManager.ConnectionStrings["AdvWorks"].
                    ConnectionString;
                    System.Data.SqlClient.SqlConnection sqlConn =
                    new System.Data.SqlClient.SqlConnection
                    (myDataString);
                    sqlConn.Open();



     Ver. 1.0                                                          Slide 9 of 26
Developing Web Applications Using ASP.NET
Database Connections and the Web.Config File (Contd.)


                Data Source Controls:
                   A data source control pulls together all the elements of
                   connecting to a database to retrieve or manipulate data.
                   These elements includes:
                    •   Provider
                    •   Connection string
                    •   Query
                • Example: SqlDataSource control
                   <asp:SqlDataSource ID="SqlDataSource1"
                   Runat="server"
                   SelectCommand="SELECT * from Customers"
                   ConnectionString="<%$
                   ConnectionStrings:AppConnString%>"
                   ProviderName="<%$
                   ConnectionStrings:AppConnString.ProviderName %>"/>


     Ver. 1.0                                                            Slide 10 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls


                Accessing Relational Databases by Using Data Source
                Controls:
                   Data source controls are provided for accessing the data
                   stored in relational databases.
                   Relational data source controls provide standard database
                   functionality for any type of database used. This functionality
                   includes:
                       Retrieval of data
                       Insertion of new data
                       Updating of existing data
                       Deletion of data




     Ver. 1.0                                                               Slide 11 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                •   The basic process of displaying data from relational
                    databases on a Web page is:
                     1. Add a data source control to the Web page, and then
                        configure it to connect to the required database.
                     2. Specify the SELECT statement in the SelectCommand
                        property of the data source control, to retrieve the data.
                     3. Bind data controls or data-aware controls to the data source
                        control.
                    If application has complex data access requirements, it may
                    not be feasible to use a data source control.
                    In such a case, data access can be coded by the
                    programmer by using ADO.NET classes.




     Ver. 1.0                                                                 Slide 12 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                Providers:
                   A provider is a class that can communicate with a specific type
                   of database or data store.
                   ASP.NET provides a number of providers that can
                   communicate with a wide variety of data stores.
                   The providers include, the .NET framework data provider for:
                    •   SQL server in the System.Data.SqlClient namespace
                    •   OLE DB in the System.Data.OleDb namespace
                    •   ODBC in the System.Data.Odbc namespace
                    •   Oracle in the System.Data.OracleClient namespace




     Ver. 1.0                                                            Slide 13 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                Format of returned Data:
                • SqlDataSource control can return data in two forms:
                     • DataSet
                     • Data reader
                •   Any of the above forms can be selected by setting
                    DataSourceMode property of the data source control.
                •   DataSet:
                     • Allows users to manipulate data after retrieving it.
                     • Is used when a user want to filter, sort, or page through data after
                       retrieving it.
                    Data reader:
                       Provides a read-only cursor that can fetch individual records.
                       Is used to return and load the data into a control on the page.




     Ver. 1.0                                                                     Slide 14 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                Caching:
                • The SqlDataSource control can cache data that it has
                  retrieved.
                • Caching can be enabled by setting EnableCaching to
                  true.
                • CacheDuration property can be set to specify the number
                  of seconds to cache data.
                • Cache dependency feature of SQL Server can also be used
                  by SqlDataSource control.
                • By using cache dependency, retrieval of data can be
                  minimized.




     Ver. 1.0                                                      Slide 15 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                Sorting and Filtering:
                 •   The SqlDataSource control can be used to filter the data
                     without rerunning the query, provided you have:
                      • Cached the data
                      • Specified DataSet as the format of the returned data
                 • FilterExpression property of SqlDataSource control
                   can be used to specify the selection criteria that are applied to
                   the data maintained by the data source control.
                 • Filter expression can be parameterized by creating special
                   FilterParameters objects.




     Ver. 1.0                                                                  Slide 16 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                Data source controls provide the following properties:
                   SelectCommand
                   UpdateCommand
                   InsertCommand
                   DeleteCommand
                To enable data editing in a Web page, templates with
                editable controls can be defined for the data controls.
                Button controls with specific CommandName arguments can
                be included to invoke specific data operations.




     Ver. 1.0                                                        Slide 17 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                Templates for data controls:
                   To use the FormView control to display data from a database
                   on a Web page:
                       Create an ItemTemplate element between the opening and closing
                       tags of the FormView control.
                       Include static label controls and the necessary markup to bind the
                       static label controls to the fields in the data source as:
                     <ItemTemplate>
                         <b>Product ID: </b>
                         <asp:Label ID="lblProductID" runat="server" Text=
                              '<%# Eval("ProductID") %>'>
                         </asp:Label><br/>
                         <b>Product Name:</b>
                         <asp:Label ID="lblProductName" runat="server"
                       Text='<%# Eval("ProductName") %>'>
                         </asp:Label><br/>
                                      <asp:Button ID="btnAdd" Text="Add review“
                                       CommandName="New“ runat="server" />
                           </ItemTemplate>
     Ver. 1.0                                                                  Slide 18 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                To use the FormView control to add new data :
                   Create an InsertItemTemplate element between the opening and
                   closing tags of the FormView control.
                   Include editable controls and the necessary markup to bind the
                   controls to the fields in the data source as:
                     <InsertItemTemplate>
                       <table width="100%">
                         <tr> <td> Product: </td>
                           <td> <% =Request.QueryString["ProductID"]%></td>
                         </tr>
                                      <tr> <td> Product Name: </td>
                                        <td> <asp:TextBox
                       ID="txtProductName"
                                              runat="server" Text='<%#
                                              Bind("ProductName") %>' /> </
                       td>
                                      </tr>




     Ver. 1.0                                                            Slide 19 of 26
Developing Web Applications Using ASP.NET
Relational Data and Data Source Controls (Contd.)


                   <tr>
                     <td>
                       <asp:Button ID="btnInsert" runat="server"
                   CommandName="Insert" Text="Save"/>
                     </td>
                     <td>
                       <asp:Button ID="btnCancel" runat="server"
                   CommandName="Cancel" Text="Cancel"/>
                     </td>
                   </tr>
                   </table>
                 </InsertItemTemplate>




     Ver. 1.0                                                      Slide 20 of 26
Developing Web Applications Using ASP.NET
XML Data and Data Source Controls


                XMLDataSource control is provided for accessing XML
                data.
                This control can be configured to retrieve data from:
                •   XML files
                •   Web services that return XML data
                •   String variables that contain XML data
                •   In-memory XMLDataDocument objects
                XML data retrieved by the XMLDataSource control is read
                only.




     Ver. 1.0                                                     Slide 21 of 26
Developing Web Applications Using ASP.NET
XML Data and Data Source Controls (Contd.)


                The basic process for displaying XML data on Web pages
                is:
                1. Add an XmlDataSource control to the Web page, and
                   configure it to connect to the required XML source.
                2. Bind data-aware controls that are capable of displaying XML
                   data to the XmlDataSource control.
                TreeView control and Xml control are example of controls
                that are capable of displaying XML data.




     Ver. 1.0                                                           Slide 22 of 26
Developing Web Applications Using ASP.NET
Object Data and Data Source Controls


                ObjectDataSource controls are provided for accessing
                the data managed by business objects.
                The functionality of the business object defines the
                functionality of the ObjectDataSource control.
                The basic process for displaying data from business objects
                on the Web pages is:
                 1. Add an ObjectDataSource control to the Web page, and
                    then configure it to connect to the required business object.
                 2. Specify the name of the method used to retrieve data from the
                    business object in the SelectMethod property.
                 3. Bind data controls or data-aware controls to the data source
                    control.




     Ver. 1.0                                                            Slide 23 of 26
Developing Web Applications Using ASP.NET
Object Data and Data Source Controls (Contd.)


                ObjectDataSource controls support the following
                properties:
                   SelectMethod
                   UpdateMethod
                   InsertMethod
                   DeleteMethod




     Ver. 1.0                                                     Slide 24 of 26
Developing Web Applications Using ASP.NET
Summary


               In this session, you learned that:
                  Database connections are defined in terms of a string that
                  specifies the properties of the connection.
                  Using Web.config file is a better approach than hard-coding the
                  connection string in a Web application.
                  Web page retrieves the details of the connection string at the
                  run time from the Web.Config file.
                  ConfigurationManager class is used to retrieve the
                  connection string at run time.
                  Data source controls are provided to access the data stored in
                  a relational database.
                  Data source controls can select, update, insert, and delete data
                  from a relational database.




    Ver. 1.0                                                             Slide 25 of 26
Developing Web Applications Using ASP.NET
Summary (Contd.)


               XMLDataSource control is provided for accessing XML data.
               XMLDataSource control provides read-only access to the
               XML data.
               ObjectDataSource control provides access to the data
               managed by business objects.
               ObjectDataSource control can display, update, insert, and
               delete object data, provided the underlying object supports
               these functionalities.




    Ver. 1.0                                                       Slide 26 of 26

More Related Content

What's hot (18)

PDF
Synopsis
Gaurav Gopal Gupta
 
PPS
05 asp.net session07
Mani Chaubey
 
PPTX
Spring database - part2
Santosh Kumar Kar
 
PPT
Session and state management
Paneliya Prince
 
PDF
Whatsnew in-my sql-primary
Kaizenlogcom
 
DOCX
Application andmulti servermanagementdba-introwhitepaper
Klaudiia Jacome
 
PPTX
Angular Data Binding
Jennifer Estrada
 
PDF
Consistent join queries in cloud data stores
João Gabriel Lima
 
DOC
2005_604_Wagner_ppr
Mary Wagner
 
PPT
SQL Server 2000 Research Series - Architecture Overview
Jerry Yang
 
PPTX
Data Handning with Sqlite for Android
Jakir Hossain
 
PPS
Actionview
Amal Subhash
 
PPTX
John Burkholder: Disaster Recovery in SharePoint 2010
SharePoint Saturday NY
 
PPTX
Sql interview-question-part-6
kaashiv1
 
PPTX
Ebook6
kaashiv1
 
PPTX
How do i connect to that
Becky Bertram
 
PPTX
SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
Michael Noel
 
PPTX
Sql bits creating a meta data driven ssis solution with biml
Marco Schreuder
 
05 asp.net session07
Mani Chaubey
 
Spring database - part2
Santosh Kumar Kar
 
Session and state management
Paneliya Prince
 
Whatsnew in-my sql-primary
Kaizenlogcom
 
Application andmulti servermanagementdba-introwhitepaper
Klaudiia Jacome
 
Angular Data Binding
Jennifer Estrada
 
Consistent join queries in cloud data stores
João Gabriel Lima
 
2005_604_Wagner_ppr
Mary Wagner
 
SQL Server 2000 Research Series - Architecture Overview
Jerry Yang
 
Data Handning with Sqlite for Android
Jakir Hossain
 
Actionview
Amal Subhash
 
John Burkholder: Disaster Recovery in SharePoint 2010
SharePoint Saturday NY
 
Sql interview-question-part-6
kaashiv1
 
Ebook6
kaashiv1
 
How do i connect to that
Becky Bertram
 
SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
Michael Noel
 
Sql bits creating a meta data driven ssis solution with biml
Marco Schreuder
 

Viewers also liked (20)

PDF
Otsuma(2010727)
真 岡本
 
PPTX
Idocaedro aplicacion
Anni Lovee
 
PPS
03 asp.net session04
Niit Care
 
PPTX
Presentación del sistema genesis y portal institucional j a
felipegomezg
 
PDF
Shizuoka pref public_library(20101020)
真 岡本
 
PPTX
Presentación1
pipe-alejo
 
PPTX
simple present tense
karwinda
 
PDF
159267237 extractos-alquimicos
geogomes the best
 
PPTX
Mi materia preferida
Alex Sandercito
 
PDF
Presentación junio
La Guía Más Útil
 
PPS
07 asp.net session10
Niit Care
 
PPTX
Mantenimiento de computo
sebassevitas
 
PPTX
CacharreAndo
YcRF
 
DOCX
Jadwal kegiatan ujian smk muhammadiyah 1
heri baskoro
 
PPS
02 asp.net session02
Niit Care
 
PDF
FEA Final Report - Jawanza Bassue
Jawanza Bassue
 
PPTX
High Altitude Research Plane_Jawanza Bassue
Jawanza Bassue
 
PPS
Aae oop xp_06
Niit Care
 
PPTX
02 penyusunan rpp
heri baskoro
 
PDF
Ki kd tkj kelas x xi dan xii
heri baskoro
 
Otsuma(2010727)
真 岡本
 
Idocaedro aplicacion
Anni Lovee
 
03 asp.net session04
Niit Care
 
Presentación del sistema genesis y portal institucional j a
felipegomezg
 
Shizuoka pref public_library(20101020)
真 岡本
 
Presentación1
pipe-alejo
 
simple present tense
karwinda
 
159267237 extractos-alquimicos
geogomes the best
 
Mi materia preferida
Alex Sandercito
 
Presentación junio
La Guía Más Útil
 
07 asp.net session10
Niit Care
 
Mantenimiento de computo
sebassevitas
 
CacharreAndo
YcRF
 
Jadwal kegiatan ujian smk muhammadiyah 1
heri baskoro
 
02 asp.net session02
Niit Care
 
FEA Final Report - Jawanza Bassue
Jawanza Bassue
 
High Altitude Research Plane_Jawanza Bassue
Jawanza Bassue
 
Aae oop xp_06
Niit Care
 
02 penyusunan rpp
heri baskoro
 
Ki kd tkj kelas x xi dan xii
heri baskoro
 
Ad

Similar to 06 asp.net session08 (20)

PPT
State management in ASP.NET
Om Vikram Thapa
 
PPS
14 asp.net session20
Niit Care
 
PPS
16 asp.net session23
Niit Care
 
PPS
05 asp.net session07
Niit Care
 
PDF
ASP.NET Difference FAQs
Umar Ali
 
PPS
07 asp.net session10
Mani Chaubey
 
PDF
Dotnet difference questions & answers Compiled-1
Umar Ali
 
PPT
.Net Project Portfolio for Roger Loving
rloving10
 
PPTX
Ch05 state management
Madhuri Kavade
 
PPSX
07 asp.net session10
Vivek Singh Chandel
 
PPSX
ASP.Net Presentation Part3
Neeraj Mathur
 
PDF
Interview preparation techniques
Umar Ali
 
PPTX
Chapter 5
application developer
 
PPS
03 asp.net session04
Mani Chaubey
 
PPT
Asp.net basic
Neelesh Shukla
 
PPTX
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Mazenetsolution
 
PPT
Asp.net.
Naveen Sihag
 
PPTX
Developing an aspnet web application
Rahul Bansal
 
PDF
Asp net interview_questions
Ghazi Anwar
 
State management in ASP.NET
Om Vikram Thapa
 
14 asp.net session20
Niit Care
 
16 asp.net session23
Niit Care
 
05 asp.net session07
Niit Care
 
ASP.NET Difference FAQs
Umar Ali
 
07 asp.net session10
Mani Chaubey
 
Dotnet difference questions & answers Compiled-1
Umar Ali
 
.Net Project Portfolio for Roger Loving
rloving10
 
Ch05 state management
Madhuri Kavade
 
07 asp.net session10
Vivek Singh Chandel
 
ASP.Net Presentation Part3
Neeraj Mathur
 
Interview preparation techniques
Umar Ali
 
03 asp.net session04
Mani Chaubey
 
Asp.net basic
Neelesh Shukla
 
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Mazenetsolution
 
Asp.net.
Naveen Sihag
 
Developing an aspnet web application
Rahul Bansal
 
Asp net interview_questions
Ghazi Anwar
 
Ad

More from Niit Care (20)

PPS
Ajs 1 b
Niit Care
 
PPS
Ajs 4 b
Niit Care
 
PPS
Ajs 4 a
Niit Care
 
PPS
Ajs 4 c
Niit Care
 
PPS
Ajs 3 b
Niit Care
 
PPS
Ajs 3 a
Niit Care
 
PPS
Ajs 3 c
Niit Care
 
PPS
Ajs 2 b
Niit Care
 
PPS
Ajs 2 a
Niit Care
 
PPS
Ajs 2 c
Niit Care
 
PPS
Ajs 1 a
Niit Care
 
PPS
Ajs 1 c
Niit Care
 
PPS
Dacj 4 2-c
Niit Care
 
PPS
Dacj 4 2-b
Niit Care
 
PPS
Dacj 4 2-a
Niit Care
 
PPS
Dacj 4 1-c
Niit Care
 
PPS
Dacj 4 1-b
Niit Care
 
PPS
Dacj 4 1-a
Niit Care
 
PPS
Dacj 1-2 b
Niit Care
 
PPS
Dacj 1-3 c
Niit Care
 
Ajs 1 b
Niit Care
 
Ajs 4 b
Niit Care
 
Ajs 4 a
Niit Care
 
Ajs 4 c
Niit Care
 
Ajs 3 b
Niit Care
 
Ajs 3 a
Niit Care
 
Ajs 3 c
Niit Care
 
Ajs 2 b
Niit Care
 
Ajs 2 a
Niit Care
 
Ajs 2 c
Niit Care
 
Ajs 1 a
Niit Care
 
Ajs 1 c
Niit Care
 
Dacj 4 2-c
Niit Care
 
Dacj 4 2-b
Niit Care
 
Dacj 4 2-a
Niit Care
 
Dacj 4 1-c
Niit Care
 
Dacj 4 1-b
Niit Care
 
Dacj 4 1-a
Niit Care
 
Dacj 1-2 b
Niit Care
 
Dacj 1-3 c
Niit Care
 

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 

06 asp.net session08

  • 1. Developing Web Applications Using ASP.NET Objectives In this session, you will learn to: Configure ViewState properties and ControlState properties for Web server controls Store and retrieve Application and Session state data Implement out-of-process session state Store and manage state data in the Cache object Explain how to store and retrieve database connections by using the Web.Config file Explain how to use data source controls to access relational data Explain how to use data source controls to access XML data Explain how to use data source controls to access object data Ver. 1.0 Slide 1 of 26
  • 2. Developing Web Applications Using ASP.NET Demo: Managing State for a Web Application Problem Statement: You are a developer in the Adventure Works organization, a fictitious bicycle manufacturer. You have been asked to assist in the development of the Business-to-Consumer (B2C) Web application and a related Business-to-Employee (B2E) extranet portal. Decisions on the design of the application have already been made. As part of the first phase of the B2C development, you have been asked to configure the behavior of Web server controls by manipulating their ViewState properties. You have also been asked to add a site-counter to the site, which will display user numbers and store data in the Application and Session objects. Ver. 1.0 Slide 2 of 26
  • 3. Developing Web Applications Using ASP.NET Demo: Managing State for a Web Application (Contd.) You will also specify how the Web application stores and manages session state data. Finally, you have been asked to implement caching by using the Cache object to store bike review data. Ver. 1.0 Slide 3 of 26
  • 4. Developing Web Applications Using ASP.NET Demo: Managing State for a Web Application (Contd.) Solution: • To solve this problem, you need to perform the following tasks: 1. Configuring ViewState Properties for Web Server Controls a. Open the Adventure Works Web site. b. Set the EnableViewState property of Web server controls. c. Test the ViewState after a Web page is submitted. d. Disable ViewState for the BikeReview.aspx page. e. Work with the MaxPageStateFieldLength property to divide the ViewState data into chunks. 2. Storing and Retrieving Application and Session State a. Initialize information in the Application object. b. Write code to increment the UserCount value when a new user session begins. c. Store Data in the Session object. d. Retrieve Application and Session state data and display it on the Web page. Ver. 1.0 Slide 4 of 26
  • 5. Developing Web Applications Using ASP.NET Demo: Managing State for a Web Application (Contd.) 1. Implementing Out-of-Process Session State a. Enable users to save their favorite trails in Session data. b. Configure IIS, and then test the application. c. Enable StateServer session management. d. Enable SQLServer session management. 2. Storing and Managing State Data in the Cache Object a. Store data and retrieve data from the Cache object. b. Define dependencies between items in the Cache object. c. Delete invalid cached data. d. Implement Change Notifications in cached data to ensure that deleted items are reloaded into the cache. Ver. 1.0 Slide 5 of 26
  • 6. Developing Web Applications Using ASP.NET Database Connections and the Web.Config File Database Connections and Connection Strings: Web applications use database connections as the underlying mechanism to perform various operations on the databases. Database connections are defined in terms of a string that specifies the properties of the connection. Different databases support different properties and therefore require different connection strings. Ver. 1.0 Slide 6 of 26
  • 7. Developing Web Applications Using ASP.NET Database Connections and the Web.Config File (Contd.) Using the Web.config File to Simplify Connection String Management: Connection strings can be hard coded into the Web application pages. This approach is difficult to manage because databases may be moved, redefined, or upgraded. This problem can be solved by using the Web.Config file to store the connection strings. This approach retrieves the details of connection strings at run time from the Web.config file. Ver. 1.0 Slide 7 of 26
  • 8. Developing Web Applications Using ASP.NET Database Connections and the Web.Config File (Contd.) This sample code shows part of a Web.Config file with a connection string: <connectionStrings> <add name="AdvWorks" connectionString="Server=MySQLSever; Database=AdventureWorks; Integrated Security=SSPI;Persist Security Info=True" providerName="System.Data.SqlClient"/> </connectionStrings> Ver. 1.0 Slide 8 of 26
  • 9. Developing Web Applications Using ASP.NET Database Connections and the Web.Config File (Contd.) Retrieving Connection Strings at Run Time: Connection string stored in the connectionStrings section of the Web.Config file, can be retrieved at run time. ConnectionStrings collection of ConfigurationManager class is used to retrieve such connection string. This sample code shows how to retrieve connection strings at run time and how to use them to open a database connection: string myDataString = ConfigurationManager.ConnectionStrings["AdvWorks"]. ConnectionString; System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection (myDataString); sqlConn.Open(); Ver. 1.0 Slide 9 of 26
  • 10. Developing Web Applications Using ASP.NET Database Connections and the Web.Config File (Contd.) Data Source Controls: A data source control pulls together all the elements of connecting to a database to retrieve or manipulate data. These elements includes: • Provider • Connection string • Query • Example: SqlDataSource control <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT * from Customers" ConnectionString="<%$ ConnectionStrings:AppConnString%>" ProviderName="<%$ ConnectionStrings:AppConnString.ProviderName %>"/> Ver. 1.0 Slide 10 of 26
  • 11. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls Accessing Relational Databases by Using Data Source Controls: Data source controls are provided for accessing the data stored in relational databases. Relational data source controls provide standard database functionality for any type of database used. This functionality includes: Retrieval of data Insertion of new data Updating of existing data Deletion of data Ver. 1.0 Slide 11 of 26
  • 12. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) • The basic process of displaying data from relational databases on a Web page is: 1. Add a data source control to the Web page, and then configure it to connect to the required database. 2. Specify the SELECT statement in the SelectCommand property of the data source control, to retrieve the data. 3. Bind data controls or data-aware controls to the data source control. If application has complex data access requirements, it may not be feasible to use a data source control. In such a case, data access can be coded by the programmer by using ADO.NET classes. Ver. 1.0 Slide 12 of 26
  • 13. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) Providers: A provider is a class that can communicate with a specific type of database or data store. ASP.NET provides a number of providers that can communicate with a wide variety of data stores. The providers include, the .NET framework data provider for: • SQL server in the System.Data.SqlClient namespace • OLE DB in the System.Data.OleDb namespace • ODBC in the System.Data.Odbc namespace • Oracle in the System.Data.OracleClient namespace Ver. 1.0 Slide 13 of 26
  • 14. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) Format of returned Data: • SqlDataSource control can return data in two forms: • DataSet • Data reader • Any of the above forms can be selected by setting DataSourceMode property of the data source control. • DataSet: • Allows users to manipulate data after retrieving it. • Is used when a user want to filter, sort, or page through data after retrieving it. Data reader: Provides a read-only cursor that can fetch individual records. Is used to return and load the data into a control on the page. Ver. 1.0 Slide 14 of 26
  • 15. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) Caching: • The SqlDataSource control can cache data that it has retrieved. • Caching can be enabled by setting EnableCaching to true. • CacheDuration property can be set to specify the number of seconds to cache data. • Cache dependency feature of SQL Server can also be used by SqlDataSource control. • By using cache dependency, retrieval of data can be minimized. Ver. 1.0 Slide 15 of 26
  • 16. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) Sorting and Filtering: • The SqlDataSource control can be used to filter the data without rerunning the query, provided you have: • Cached the data • Specified DataSet as the format of the returned data • FilterExpression property of SqlDataSource control can be used to specify the selection criteria that are applied to the data maintained by the data source control. • Filter expression can be parameterized by creating special FilterParameters objects. Ver. 1.0 Slide 16 of 26
  • 17. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) Data source controls provide the following properties: SelectCommand UpdateCommand InsertCommand DeleteCommand To enable data editing in a Web page, templates with editable controls can be defined for the data controls. Button controls with specific CommandName arguments can be included to invoke specific data operations. Ver. 1.0 Slide 17 of 26
  • 18. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) Templates for data controls: To use the FormView control to display data from a database on a Web page: Create an ItemTemplate element between the opening and closing tags of the FormView control. Include static label controls and the necessary markup to bind the static label controls to the fields in the data source as: <ItemTemplate> <b>Product ID: </b> <asp:Label ID="lblProductID" runat="server" Text= '<%# Eval("ProductID") %>'> </asp:Label><br/> <b>Product Name:</b> <asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'> </asp:Label><br/> <asp:Button ID="btnAdd" Text="Add review“ CommandName="New“ runat="server" /> </ItemTemplate> Ver. 1.0 Slide 18 of 26
  • 19. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) To use the FormView control to add new data : Create an InsertItemTemplate element between the opening and closing tags of the FormView control. Include editable controls and the necessary markup to bind the controls to the fields in the data source as: <InsertItemTemplate> <table width="100%"> <tr> <td> Product: </td> <td> <% =Request.QueryString["ProductID"]%></td> </tr> <tr> <td> Product Name: </td> <td> <asp:TextBox ID="txtProductName" runat="server" Text='<%# Bind("ProductName") %>' /> </ td> </tr> Ver. 1.0 Slide 19 of 26
  • 20. Developing Web Applications Using ASP.NET Relational Data and Data Source Controls (Contd.) <tr> <td> <asp:Button ID="btnInsert" runat="server" CommandName="Insert" Text="Save"/> </td> <td> <asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel"/> </td> </tr> </table> </InsertItemTemplate> Ver. 1.0 Slide 20 of 26
  • 21. Developing Web Applications Using ASP.NET XML Data and Data Source Controls XMLDataSource control is provided for accessing XML data. This control can be configured to retrieve data from: • XML files • Web services that return XML data • String variables that contain XML data • In-memory XMLDataDocument objects XML data retrieved by the XMLDataSource control is read only. Ver. 1.0 Slide 21 of 26
  • 22. Developing Web Applications Using ASP.NET XML Data and Data Source Controls (Contd.) The basic process for displaying XML data on Web pages is: 1. Add an XmlDataSource control to the Web page, and configure it to connect to the required XML source. 2. Bind data-aware controls that are capable of displaying XML data to the XmlDataSource control. TreeView control and Xml control are example of controls that are capable of displaying XML data. Ver. 1.0 Slide 22 of 26
  • 23. Developing Web Applications Using ASP.NET Object Data and Data Source Controls ObjectDataSource controls are provided for accessing the data managed by business objects. The functionality of the business object defines the functionality of the ObjectDataSource control. The basic process for displaying data from business objects on the Web pages is: 1. Add an ObjectDataSource control to the Web page, and then configure it to connect to the required business object. 2. Specify the name of the method used to retrieve data from the business object in the SelectMethod property. 3. Bind data controls or data-aware controls to the data source control. Ver. 1.0 Slide 23 of 26
  • 24. Developing Web Applications Using ASP.NET Object Data and Data Source Controls (Contd.) ObjectDataSource controls support the following properties: SelectMethod UpdateMethod InsertMethod DeleteMethod Ver. 1.0 Slide 24 of 26
  • 25. Developing Web Applications Using ASP.NET Summary In this session, you learned that: Database connections are defined in terms of a string that specifies the properties of the connection. Using Web.config file is a better approach than hard-coding the connection string in a Web application. Web page retrieves the details of the connection string at the run time from the Web.Config file. ConfigurationManager class is used to retrieve the connection string at run time. Data source controls are provided to access the data stored in a relational database. Data source controls can select, update, insert, and delete data from a relational database. Ver. 1.0 Slide 25 of 26
  • 26. Developing Web Applications Using ASP.NET Summary (Contd.) XMLDataSource control is provided for accessing XML data. XMLDataSource control provides read-only access to the XML data. ObjectDataSource control provides access to the data managed by business objects. ObjectDataSource control can display, update, insert, and delete object data, provided the underlying object supports these functionalities. Ver. 1.0 Slide 26 of 26