aspdotnet
aspdotnet
NET
• ASP stands for Active Server Pages
• ASP is a development framework for building web pages.
• ASP and ASP.NET are server side technologies.
• Both technologies enable computer code to be executed by an
Internet server.
• When a browser requests an ASP or ASP.NET file, the ASP engine
reads the file, executes any code in the file, and returns the result to
the browser.
Classic ASP - Active Server Pages
Control events This event is used to handle specific control events such as Button control' Click
event.
LoadComplete This event occurs at the end of the event-handling stage.
We can use this event for tasks that require all other controls on the page be loaded.
PreRender This event occurs after the page object has created all controls that are required in
order to render the page.
PreRenderComplet This event occurs after each data bound control whose DataSourceID property is set
e calls its DataBind method.
SaveStateComplet It is raised after view state and control state have been saved for the page and for all
e controls.
Render This is not an event; instead, at this stage of processing, the Page object calls this
method on each control.
ASP.NET Web Forms
• Web Forms are web pages built on the ASP.NET Technology.
• It executes on the server and generates output to the browser.
• It is compatible to any browser to any language supported by .NET
common language runtime.
• It is flexible and allows us to create and add custom controls.
• We can use Visual Studio to create ASP.NET Web Forms. It is an IDE
(Integrated Development Environment) that allows us to drag and
drop server controls to the web forms.
• It also allows us to set properties, events and methods for the
controls. To write business logic, we can choose any .NET language
like: Visual Basic or Visual C#.
• Web Forms are made up of two components: the visual portion (the
ASPX file), and the code behind the form, which resides in a separate
class file.
• ASP.NET provides various controls like: server controls and HTML
controls for the Web Forms.
Server Controls
Control Name Applicable Events Description
Label None It is used to display text on the HTML page.
TextBox TextChanged It is used to create a text input in the form.
Button Click, Command It is used to create a button.
LinkButton Click, Command It is used to create a button that looks similar to the hyperlink.
Hyperlink None It is used to create a hyperlink control that responds to a click event.
ListBox SelectedIndexCnhaged It is used to create a ListBox control like the HTML control.
DataGrid CancelCommand, EditCommand, DeleteCommand, It used to create a frid that is used to show data. We can also perform
ItemCommand, SelectedIndexChanged, PageIndexChanged, paging, sorting, and formatting very easily with this control.
SortCommand, UpdateCommand, ItemCreated,
ItemDataBound
DataList CancelCommand, EditCommand, DeleteCommand, It is used to create datalist that is non-tabular and used to show data.
ItemCommand, SelectedIndexChanged, UpdateCommand,
ItemCreated, ItemDataBound
Repeater ItemCommand, ItemCreated, ItemDataBound It allows us to create a non-tabular type of format for data. You can bind
the data to template items, which are like bits of HTML put together in a
specific repeating format.
Submit Button Automatically POSTs the form data to the specified page listed in the Action
attribute in the FORM tag
Password Field An input area on an HTML form, although any characters typed into this field
are displayed as asterisks
CheckBox Gives the user a check box that they can select or clear
Radio Button Used two or more to a form, and allows the user to choose one of the controls
(8) ADO.NET
It is the technology used for working with data and databases. It provides access
to data sources like SQL server, OLE DB, XML etc. The ADO.NET allows
connection to data sources for retrieving, manipulating, and updating data.
(13) LINQ
It imparts data querying capabilities to .Net languages using a syntax which is
similar to the tradition query language SQL.
ASP.NET - Example
• An ASP.NET page is made up of a number of server controls along
with HTML controls, text, and images.
• ASP.NET runtime controls the association between a page instance
and its state.
• An ASP.NET page is an object of the Page or inherited from it.
• All the controls on the pages are also objects of the related control
class inherited from a parent Control class.
• When a page is run, an instance of the object page is created along
with all its content controls.
• An ASP.NET page is modular in nature and can be divided into the
following core sections:
• Page Directives
• Code Section
• Page Layout
Page Directives
• The page directives set up the environment for the page to run.
• The @Page directive defines page-specific attributes used by ASP.NET
page parser and compiler.
• Page directives specify how the page should be processed, and which
assumptions need to be taken about the page.
• It allows importing namespaces, loading assemblies, and registering
new controls with custom tag names and namespace prefixes.
Code Section
• It provides the handlers for the page and control events along with
other functions required.
• ASP.NET follows an object model, these objects raise events when
some events take place on the user interface, like a user clicks a
button or moves the cursor.
• The event handlers are nothing but functions bound to the controls.
• The code section or the code behind file provides all these event
handler routines, and other functions used by the developer.
• The page code could be precompiled and deployed in the form of a
binary assembly.
Page Layout
• The page layout provides the interface of the page.
• It contains the server controls, text, inline JavaScript, and HTML tags.
• <!-- Layout -->
• <!-- directives --> • <html>
• <% @Page Language="C#" %> • <head>
• <title> Change to Upper Case </title>
• </head>
• <!-- code section -->
•
• <script runat="server"> • <body>
• <h3> Conversion to Upper Case </h3>
•
• private void convertoupper(object
sender, EventArgs e) • <form runat="server">
• <input runat="server" id="mytext" type="text" />
• { • <input runat="server" id="button1" type="submit"
• string str = mytext.Value; value="Enter..." OnServerClick="convertoupper"/>
• changed_text.InnerHtml = str.ToUpper(); •
• <hr />
• } • <h3> Results: </h3>
• </script> • <span runat="server" id="changed_text" />
• </form>
•
•
• </body>
Using Visual Studio IDE
• drag the controls into the design view:
• The content file is automatically developed.
• add the Button1_Click routine,