Advanced Web Programming: Language Library
Advanced Web Programming: Language Library
V
Advanced Web Programming
Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75
2. Base Class Library (BCL) : The .NET Framework class library is a library of classes,
interfaces, and value types that provide access to system functionality. It is the
foundation on which .NET Framework applications, components, and controls are built.
Following are different types of applications that can make use of .net class library.
(i) Windows Application (ii) Console Application (iii) Web Application
(iv) XML Web Services (v) Windows Services
Developers just need to import the BCL in their language code and use its predefined
methods and properties to implement common and complex functions like reading and
writing to file, graphic rendering, database interaction, and XML document manipulation.
-1-
Vidyalankar : T.Y. B.Sc. (IT) AWP
3. Common Language Runtime : The Common Language Runtime (CLR), the virtual
machine component of Microsoft's .NET framework, manages the execution of .NET
programs. A process known as just-in-time compiler that converts the compiled code into
machine instructions which the computer's CPU then executes. The CLR provides
additional services including memory management, type safety, exception
handling, garbage collection, security and thread management. All programs written for
the .NET framework, irrespective of programming language, are executed by the CLR.
-2-
Prelim Question Paper Solution
using System;
namespace inheritance1
{
class A
{
public virtual void display()
{
Console.WriteLine("class A display");
}
}
class B : A
{
public override void display()
{
Console.WriteLine("class B display");
}
}
class C : A
{
public override void display()
{
Console.WriteLine("class C display");
}
}
class Program
{
static void Main(string[] args)
{
-3-
Vidyalankar : T.Y. B.Sc. (IT) AWP
A r; //reference of A
r = new A();
r.display();
r = new B();
r.display();
r = new C();
r.display();
Console.ReadLine();
}
}
}
class Program
{
static void Main (String [ ] args)
{
A a1 = new A ( );
B b1 = new B ( );
C c1 = new C ( );
A r; // reference of A
r = a1;
r : display ( );
r = b1;
r : display ( );
r = c1;
r : display ( );
C.RL ( );
}
}
}
Output:
-4-
Prelim Question Paper Solution
Components of Assembly :
Manifest
It describes the assembly. The manifest file contains all the metadata needed to
specify the assembly's version requirements, security identity, and all metadata needed
to define the scope of the assembly and resolve references to resources and classes.
Type Metadata
It contains metadata, which describes each and every type (class, structure,
enumeration, etc).
MSIL
It contains Intermediate language code.
Resources
It contains bitmaps, icons, audios and other types of resources.
Defining a Namespace:
A namespace definition begins with the keyword namespace followed by the namespace name
as follows :
namespace namespace_name
{
// code declarations
}
Example:
using System;
namespace nestednamespace
{
namespace n1
{
public class A
{
public void f1()
{
Console.WriteLine("f1 of A of n1");
}
}
}
namespace n2
{
-5-
Vidyalankar : T.Y. B.Sc. (IT) AWP
public class A
{
public void f1()
{
Console.WriteLine("f1 of A of n2");
}
}
}
class program
{
static void Main(string[] args)
{
n2. A a1 = new n2.A();
a1.f1();
n1.A a2 = new n1.A();
a2.f1();
Console.ReadLine();
}
}
}
Output:
-6-
Prelim Question Paper Solution
3. ASP.NET retrieves state information from the hidden view state field and updates the
controls accordingly.
4. The Page.Load event is fired.
5. The appropriate change event is fired for the control. (If more than one control has
been changed, the order of change events is undetermined.)
6. The Page.PreRender event fires, and the page is rendered (transformed from a set of
objects to an HTML page).
7. Finally, the Page.Unload event is fired.
8. The new page is sent to the client.
Example:
<asp:TextBox id="t1" runat="server" />
<asp:TextBox id="t2" runat="server" />
<asp:CompareValidatorid="compare"ControlToValidate="txt1"
ControlToCompare="t2"ForeColor="Pink" BackColor="maroon" Type="String"
Text="Validation Failed!" runat="server"/>
Example:
<asp:Label runat="server" Text="Enter a username: "/>
<asp:TextBox id="t1" runat="server"/>
<asp.Button Text-"Submit" runat="server"/><br/>
<asp:Label id= "msg" runat= "server"/><br/>
<asp: Custom Validator ControlTo Validate="t1"
OnServerValidate="user"Text="Enter proper value!"runat="server"/>
-7-
Vidyalankar : T.Y. B.Sc. (IT) AWP
<Ad>
<!-- First ad here. -->
</Ad>
<Ad>
<!-- Second ad here. -->
</Ad>
</Advertisements>
-8-
Prelim Question Paper Solution
To display SiteMapPath control in all your pages automatically, add it in the master page
of the website. To Create a SiteMapPath Control follow the following steps :
(i) Open the master page in design View and drag a SiteMapPath control from the
Navigation Toolbox to the page.
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
(ii) Save the changes and then request any Content page in the browser.
(iii) Content page shows the path from the root of the site to the current page. While
navigating through the site the SiteMapPath control changes the path for each page.
-9-
Vidyalankar : T.Y. B.Sc. (IT) AWP
(i) try :
Í It contains block of code that needs to be monitored for occurrence of
exception.
Í If exception occurs within try block there is a chance of it being handled.
Í try block can be followed by either catch or finally or both.
(ii) catch :
Í It contains exception handling code.
(iii) throw :
Í used to throw exception manually.
Í Mainly used for throwing user defined exception.
(iv) finally :
Í Contains code that needs to be executed irrespective.
Exception is generated or not.
Generated exception is handled or not.
- 10 -
Prelim Question Paper Solution
Q.3(d) Compare Session State and Application State Management techniques. [5]
Ans.:
Session State Application State
1. It allows all .NET data types for the It Allows all .NET data types
default in-process storage mode. All
serializable .NET data types if you use an
out-of-process storage mode.
2. The storage location is Server memory, The storage location is Server memory.
state service, or SQL Server, depending
on the mode you choose.
3. Times out after a predefined period The lifetime of the application
(usually 20 minutes, but can be altered (typically, until the server is
globally or programmatically). rebooted).
4. The scope is the whole ASP.NET The scope is the whole ASP.NET
application. application. Unlike other methods,
application data is global to all users.
- 11 -
Vidyalankar : T.Y. B.Sc. (IT) AWP
5. It is very secure, because data is never It is very secure, because data is never
transmitted to the client transmitted to the client.
6. The performance is slow when storing a The performance is slow when storing a
large amount of information, especially if large amount of information, because this
there are many users at once, because data will never time out and be removed.
each user will have their own copy of
session data.
7. Typical used for Storing items in a Typical used for storing any type of
shopping basket global data
3. The ID Selector :
The ID selector is always prefixed by a hash symbol (#) and enables you to refer to a
single element in the page. Within an HTML or ASPX page, you can give an element a
unique ID using the id attribute. With the ID selector, you can change the behavior for
that single element, example :
#IntroText
{
font-style: italic;
}
Because you can reuse this ID across multiple pages in your site (it only has to be unique
within a single page), you can use this rule to quickly change the appearance of an
element that you use once per page, but more than once in your site, for example with
the following HTML code:
<p id = "IntroText">I am italic because I have the right ID.</p>
<p id = "BodyText"> I am NOT italic because I have a different ID.</p>
Here the #IntroText slector changes the font of the first paragraph which has the
matching id attribute but leaves the other paragraph unmodified. ID selectors are case
sensitive, ensure that id attribute and the selector always use the same casing.
- 12 -
Prelim Question Paper Solution
of unrelated HTML elements. The following rule changes the text to red and bold for all
HTML elements that have their class attributes set to Highlight :
Highlight
{
font-weight: bold; color: Red;
}
The following code snippet uses the Highlight class to make the contents of a <span>
element and a link (<a>) appear with a bold typeface :
This is normal text but <span class = "Highlight"> this is Red and Bold.</span>
This is also normal text but <a href="CssDemo.aspx" class = "Highlight">this link is Red
and Bold as well.</a>
Q.3(f) Explain relation between master page and content page. [5]
Ans.: Master page provides a framework within which the content from other pages can be
displayed.
It provides elements such as headers, footers, style definitions, or navigation bars that
are common to all pages in your web site. So the Content Pages need not have to
duplicate code for shared elements within your Web site.
It gives a consistent look and feel for all pages in your application.
The master page layout consists of regions where the content from each content page
should be displayed.
These regions can be set using ContentPlaceHolder server controls.
These are the regions where you are going to have dynamic content in your page.
A derived page also known as a content page is simply a collection of blocks the runtime
will use to fill the regions in the master.
To provide content for a ContentPlaceHolder, you use another specialized control, called
Content.
The ContentPlaceHolder control and the Content control have a one-to-one relationship.
For each ContentPlaceHolder in the master page, the content page supplies a matching
Content control.
ASP.NET links the Content control to the appropriate ContentPlaceHolder by matching
the ID of the ContentPlaceHolder with the Content ContentPlaceHolderID property of
the corresponding Content control.
- 13 -
Vidyalankar : T.Y. B.Sc. (IT) AWP
Select command
Database server
Connection Database
Insert, Delete or
Update command
The connected environment provides forward-only, read-only access to data in the data
source and the ability to execute commands against the data source. The connected
classes provide a common way to work with connected data regardless of the underlying
data source.
They include Connection, Command,DataReader, Transaction, ParameterCollection, and
Parameter classes.
Connected Mode Classes :
The following classes are used by ADO.NET to communicate directly with the data
source :
Connection : Maintains information required to connect to the data source through
a connection string. The connection string contains information such as the name of
the data source and its location, and authorization credentials and settings.
Command : Executes SQL statements or stored procedures against the data source.
The command class has a ParameterCollection object containing Parameter objects
that allow parameterized SQL statements and stored procedures to be used against
the data source.
DataReader : Provides connected forward-only, read-only access to the data
source. It is optimized forspeed.
Parameter : Allows parameters for both parameterized queries and stored
procedures to be defined and set to appropriate values. The Parameter class is
accessed through the ParametersCollection object within a Command object. It
supports input and output parameters as well as return values from stored
procedures.
Transaction : Allows transactions to be created on a connection so that multiple
changes to data in a data source are treated as a single unit of work and either all
committed or cancelled.
- 14 -
Prelim Question Paper Solution
A command object uses a connection object to figure out which database to communicate
with. We can use a command object alone, to execute a command directly, or assign a
reference to a command object to an SqlDataAdapter.
- 15 -
Vidyalankar : T.Y. B.Sc. (IT) AWP
Repeated-value binding can also simplify your life by supporting advanced formatting and
template options that automatically configure how the data should look when it’s placed
in the control.
To create a data expression for list binding, you need to use a list control that explicitly
supports data binding.
ASP.NET provides a number of list controls :
Í ListBox, DropDownList, CheckBoxList, and RadioButtonList : These web controls
provide a list for a single field of information.
Í HtmlSelect : This server-side HTML control represents the HTML <select> element
and works essentially the same way as the ListBox web control.
Í GridView, DetailsView, FormView, and ListView : These rich web controls allow
you to provide repeating lists or grids that can display more than one field of
information at a time.
The GridView data can be sorted based on any or all of its columns. To sort GridView data,
following are the steps :
Set AllowSorting attribute of GridView to True.
Also set SortExpression property of columns to respective field from database to sort.
Paging refers to the ability of GridView control to display bound data one page at a time.
Users can arbitrarily select pages from a GridView. To enable paging feature of a GridView :
Set AllowPaging property of GridView control to true.
Set PageSize property to no of records we want in each page.
Example :
<asp:gridview AllowSorting="true" AllowPaging="true" PageSize="5" ID="Gridview1"
runat="server" DataKeyNames="pid" DataSourceID="SqlDS" >
<Columns>
- 16 -
Prelim Question Paper Solution
Features :
XSDs can be extensible for future additions.
XSD is richer and more powerful than DTD.
XSD is written in XML.
XSD supports data types.
- 17 -
Vidyalankar : T.Y. B.Sc. (IT) AWP
There are four different kinds of Windows authentication options available that can be
configured in IIS :
Anonymous Authentication : In this, IIS does not perform any authentication check and
allows access to any user to the ASP.NET application.
Basic Authentication : In this, a Windows user name and password have to be provided
to connect. This information is sent over the network in plain text and hence this is an
insecure kind of authentication.
Digest Authentication : It is almost same as Basic Authentication but the password is
hashed before it is sent across the network.
Integrated Windows Authentication : In this, password is not sent across the network
and some protocols are used to authenticate users. It provides the tools for
authentication and strong cryptography is used to help to secure information in systems
across entire network.
- 18 -
Prelim Question Paper Solution
It will allow only user user1 and deny all other users to access that application. If you want
to give permission for more users then just add usernames separated with comma like
user2,user3 etc.
If you want to allow only admin roles to access the application and deny permission for all
the roles, then write the following code in web.config.
<system.web>
<Authorization>
<allow roles="Admin"/>
<deny users="*"/>
</Authorization>
</system.web>
Web browser
Web page
DOM Events
1 Web server
5
2
JavaScript
Application server
and
XMLHttpRequest 3
- 19 -
Vidyalankar : T.Y. B.Sc. (IT) AWP
General Form :
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Properties :
(i) DisplayAfter : It determines the time in milliseconds that the control has to wait
before it displays its content.
(ii) DynamicaLayout : It determine whether the progress template is dynamically rendered.
(iii) Visible : Indicated whether the control is visible and rendered.
(iv) EnableViewState : Whether the control automatically saves its state for the use in
round trips.
General Form:
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
</asp:UpdateProgress>
- 20 -