Asp QB
Asp QB
Asp QB
NET
Chap 1- Introduction to Asp.net
1) What is ASP.Net? Explain the page structure of asp.net.
It is a web framework designed and developed by Microsoft. It is used to
develop websites, web applications and web services. It provides
fantastic integration of HTML, CSS and JavaScript. It was first released in
January 2002. It is built on the Common Language Runtime (CLR) and
allows programmers to write code using any supported .NET language.
ASP.NET provides three development styles for creating web
applications:
1. Web Forms:
It is an event driven development framework. It provides server-side
controls and events to create web application.
2. ASP.NET MVC:
It gives us a MVC (Model View Controller), patterns-based way to build
dynamic websites.
3. ASP.NET Web Pages:
It is used to create dynamic web pages. It provides fast and lightweight
way to combine server code with HTML.
Structure of Asp.Net Page:
An ASP.NET page is made up of a number of server controls along with
HTML controls, text, and images. Sensitive data from the page and the
states of different controls on the page are stored in hidden fields that
form the context of that page request. An ASP.NET page is also a server
side file saved with the .aspx extension. It is modular in nature and can
be divided into the following core sections:
1. 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.
2. Code Section:
The code section provides the handlers for the page and control events
along with other functions required.
3. Page Layout:
The page layout provides the interface of the page. It contains the server
controls, text, inline JavaScript, and HTML tags.
2) What is single page model? Explain its advantage and disadvantage.
In the single-file page model, a Web Forms page's markup and its
programming code are in the same physical .aspx file. The programming
code is in a script block that contains the attribute runat="server" to mark
it as code that ASP.NET should execute.
Example:
<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click(Object sender, EventArgs e)
{
Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
<html>
<head>
<title>Single-File Page Model</title>
</head>
<body>
<form runat="server">
<div>
<asp:Label id="Label1" runat="server" Text="Label">
</asp:Label><br />
<asp:Button id="Button1" runat="server" onclick="Button1_Click"
Text="Button">
</asp:Button>
</div>
</form>
</body>
</html>
Advantages:
In pages where there is not very much code, the convenience of
keeping the code and markup in the same file can outweigh For
example, it can be easier to study a single-file page because you can
see the code and the markup in one place.
Pages written using the single-file model are slightly easier to deploy
or to send to another programmer because there is only one file.
Managing files in a source code control system is slightly easier,
because the page is self-contained in a single file.
Disadvantages:
Each time when there is a request for page it compiles the code each
time then server the page Like classic asp because inline code cannot
create dll.
we are not able to see the code, only the results are rendered when
the page runs.
4) State the difference between Single Page Model and Code behind
model.
Single page Model Code Behind Model
The business logic is in The HTML and controls are in
<script> blocks in the same the .aspx file, and the
.aspx file that contains the business logic is in a separate
HTML and controls. .aspx.cs or .aspx.vb file.
When the page is deployed, All project class files (without
the source code is deployed the .aspx file ) are compiled
along with the Web Forms into a .dll file, which are
page, since it is physically in deployed to the server
the .aspx file. Though, we are without any source code.
not able to see the code, only When a request for the page
the results are rendered is received, then an instance
when the page runs. of the project .dll file is
created and executed.
The .aspx file derives from the The code for the page is
Page class. compiled into a separate
class from which the .aspx file
derives.
When we write inline code, The code-behind approach
we write code in the same also improved productivity
page with Html code (at some level) since the
between scripting tags. So, designer and the developer
each time when there is a can continue working
request for page it compiles simultaneously on the same
the code each time then set of application. It's also
server the page Like classic easier to build & test the UI
asp because inline code and the business logic (DLL) -
cannot create dll. separately or combined.
Properties:
1. MachineName: Returns the name of the server that hosts the Web application
2. ScriptTimeout: Indicates the number of seconds that are allowed to elapse when
processing the request before a timeout error is sent to the client
Methods:
1. ClearError() : Clears the last exception from memory
2. CreateObject() : Creates a COM object on the server
3. Execute() : Executes an ASPX page within the current requested page
4. GetLastError() : Returns the last exception that occurred on the Web server
4) Write a short note on http application state.
The ASP.NET application is the collection of all web pages, code and other files within a
single virtual directory on a web server.
When information is stored in application state, it is available to all the users. To provide
for the use of application state, ASP.NET creates an application state object for each
application from the HTTPApplicationState class and stores this object in server
memory.
This object is represented by class file global.asax.
Application State is mostly used to store hit counters and other statistical data.
Properties:
1. Itemname: - The value of the application state item with the specified name.
2. Count:- This is the default property of the HttpApplicationState class. The number
of items in the application state collection.
Methods:
1. Clear: Removes all the items from the application state collection.
2. Removename: Removes the specified item from the application state collection.
3. RemoveAll: Removes all objects from an HttpApplicationState collection.
5) Write a short note on http session state.
When a user connects to an ASP.NET website, a new session object is created. When
session state is turned on, a new session state object is created for each new request.
This session state object becomes part of the context and it is available through the
page.
Session state is generally used for storing application data such as inventory, supplier
list, customer record, or shopping cart. It can also keep information about the user and
his preferences, and keep the track of pending operations.
Properties:
1. SessionID: The unique session identifier
2. Itemname: The value of the session state item with the specified name.
3. Count: The number of items in the session state collection.
Methods:
1. Clear: Removes all the items from session state collection.
2. Removename: Removes the specified item from the session state collection.
3. RemoveAll: Removes all keys and values from the session-state collection.
6) Write a short note on view state.
ViewState is a important client side state management technique. ViewState is used to
store user data on page at the time of post back of web page.
ViewState does not hold the controls, it holds the values of controls. It does not restore
the value to control after page post back.
ViewState can hold the value on single web page, if we go to other page using
response.redirect then ViewState will be null.
ViewState stores data on single page. ViewState is client side state management
technique
Example:
//Store the value in viewstate
ViewState[“name”]=”Eagle Computers”;
//Retrieve information from viewstate
string value=ViewState[“name”].ToString();