Anda di halaman 1dari 25

T.Y. B.Sc. (IT) : Sem.

ASP.NET with C#

Prelim Question Paper Solution

Time : 2 Hrs.]

[10]
[10
[5
[5]

Vi
dy
al
an
ka
r

Q.1
Attempt the following (any TWO)
Q.1(a) Write a program to find reverse of number.
(A)
Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[Marks : 75

namespace palindrome
{
class program
{
static void Main (String args [ ])
{
int n, r, d = 0, n1;
1;
Console.WriteLine("Enter
riteLine("Enter
"Enter the no :");
n = Convert.ToInt32(Console.ReadLine(
));
vert.ToInt32(Console.ReadLine(
oInt32(Console.ReadL
))
n = n1;
1;

while (n1
n1 ! = 0)
0
{
r = n1%10
n1%10;
d = d * 10 + r;
n1 = n1/10;
}
Console.WriteLine("Reverse of "+ n + "is" + d );
Console.WriteL
if (d = = n)
Console.WriteLine (n + "is palindrome");
Console.W
else
Console.WriteLine(n + is not palindrome);
Co

[1 mark]

[3 mark]

[1 mark]

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

ka

Q.1(b) Explain out parameter.


[5]
(A)
Out Parameter
Out parameter works similar to ref. parameter however it has following
differences
[1 mark]
[1 mar
(i) It is illegal to used unassigned variable as ref parameter.
mark]
he function
tion
(ii) An out parameter must be treated as unassigned value by the
[1 mark
mark]
that uses it.
namespace NP1
{
[2 mark]
class P1
{
static void main (string [ ]args)
{
int a = {11, 12, 13, 14, 15};
ble.
int p; // unassigned variable.
int max = FindMax (a, outt p);
Console.WriteLine ("The
The largest
gest element = " + ma
max + "at position
= " + p);
}
static int findMax
ax (int
nt [ ]a, out int p)
p
{
int m;
m = a[0];
p = 0;
for(int i = 0; i < a.length;
a.length i++)
{
if(m < a[i])
a[i]
{
m = a[i];
p = i;
}
}
return m;
}
}
}

Prelim Paper Solution

Q.1(c) Explain Exception Handling.


[5]
(A)
Exception Handling
[1 mark]
It is a mechanism to handle runtime problems generated in the program.
In C/C++
The runtime problem causes abnormal termination of program howeverr in
Java / C++.

Vi
dy
al
an
ka
r

The runtime problem causes abnormal termination of program


rogram
m however in
java/C#.

There is a mechanism to take corrective action.


on. In case of exception.
exception
Exception handing is implemented using following
ng keywords.
i) try
It contains code that needs to be monitored
onitored for occur
occurrence of
exception.
It exception is generated in try block
of it being
ck there is chance
cha
handled. When exception is generated
ated outside the try block, it
i cannot be
handled and causes abnormal
[1 mark]
mal program
ogram termination.
ii) catch block
It contains exception
ption handling code.
code.

[1 mark]

iii) throw
It is used
exception
normally used for throwing
sed to manually throw an ex
cept
user-defined
[1 mark]
-defined exception.
xception.
iv)) finally
ly
It contains code that must
be
m
b executed whether exception is generated
orr not or generated exce
exception is handled or not it is executed before
ex
method
[1 mark]
ethod returns to its caller.
c

Q.1(d)
1(d) Explain CLR.
CL
[5]
(A)
CLR (COMMON
LANGUAGE
RUNTIME)
[2 mark]
(COM
L
of the most essential components of .net framework.
x CLR is one o
environment where all programs using .net technologies over
x CLR is the
t
executed.
execu
CLR allows the execution of code across different platform by
x CL
transmiting code into IL (Intermediate Language).
x IL is converted into machine language during execution by JIT compiler
(Just-In-Time).
x During JIT compilation the code is also check for type safety.
3

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Vi
dy
al
an
ka
r

Type safety ensure that object are always accessed in compatible way.
If value of 8 byte given to 4 byte then error will occur by CLR and error
will attempt to trap.
CLR consist of common rules that must be followed by all language using
.net framework these set of rules are called as Common Language
angua
Specification (CLS).
The CLS enables an object or application to interact with the bjects
ects o
or
application of other language.
The classes that follows the rules specified by CLS are termed
ermed as CLS
compliant classes.
One of the specification defined in CLS is Common
mon Typed
ped System (CTS).
CTS provides a type system that is common across
cross all languages.
CTS defines rules that ensure that the data object written in va
various
languages are able to interact with each
h other.
r.
During execution CLR performs following
owing steps
teps :
(a) Loading assemblies & identifies
[1 mark]
fies name
me spaces
x assemblies are loaded
assemblies the
d into memory after loadin
loading assem
CLR will identifies namespace
pace for the code in assemblies.
assemb
x namespaces are
package
in java)
e collections of classes (similar
(s
p
namespaces are used to organised the classes
in hierarchy.
c
x The namespaces
can not be change.
spaces have
ve public access
access & this c

x
x
x

(b) JIT Compilation


[1 mark]
mpilation
n (Just-in-time)
Before
converted into machine language using
re execution
ecution the IL is converte
c
JIT complier.
mpli
following points :
The IL code is examined for
f foll
x The memory location
l
that code needs to access are available.
x methods are called
only
ca
onl through properly define types
correctly generated.
x IL
L has been cor
correct

Collection
[1 mark]
(c) Garbage C
Collectio
x The garbage
garbag collection process begins after the JIT compilation.
manages the allocation & de-allocation of memory for an
x It man
application.
appli
When you create an object the CLR allocates memory for the
x W
object from managed heap.

Prelim Paper Solution

Vi
dy
al
an
ka
r

Q.2
Attempt the following (any TWO)
[10]
Q.2(a) Explain ASP.NET life cycle.
[5]
(A)
ASP.NET Page LifeCycle
[1 mark]
Sequence of events that are fixed in life cycle of ASP.NET web page are as
follows :
a) Page_Init
b) Load ViewState
c) Load Post Back Data
d) Page_Load
e) Raise PostDataChangedEvent
f) Raise PostBackEvent
BackEvent
g) Page_PreRender
h) SaveViewsState
ewsState
ate
i) Page_Render
j) Page_Unload
e_Unload
Page_Init
[1 mark]
mar
It contains initialization code for example the
e server
ver controls are initialized
initial
to their default values.

LoadViewState
[1 mark]
m
It restores the pages view state information
state.
formation
n from its last saved
s
stat
Load Post Back Data
It populates the server control
data.
trol in your
tro
our web with the posted
p
d

[1 mark]

PageLoad
[1 mark]
It restores the control
page
ntrol the
he values of
o the web
w
pag i.e. the data will be
binded to the data
a controls.
rols.

Page-PreRender
nder
[1 mark]
It is called
here we can add code to make
d prior to the rendering
ndering of
o page event
ev
changes
ess in the rendered output.
Save
ave View
w State
It is responsible for saving view state information of web page.

[1 mark]

PageRender
[ mark]
It render the con
content of web page in the webbrowser you can make changes
output here.
to the rendere
rendered outpu

Page Unloa
Unload
[ mark]
event in life cycle of ASP.NET page. It is called after the page
It is the last e
and is responsible for releasing the resource and
has been rendered
r
discarding the web page from memory.
discardin

Q.2(b)) Explain
CSS & its types.
Ex
[5]
(A)
CSS offers with set of options to change every aspects of web sites. [ mark]
x CSS is understood by all the browsers and so it is used for visual
presentation of web pages.
5

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

x
x

It separates presentation from data.


It decrease the bandwidth and direct change with every request.

Types:
[1 mark]
InclineCss
It uses style distribute of a very element on which we want to apply
ly style
>It cannot be nemed
[1 mark]

Vi
dy
al
an
ka
r

Example
<html>
<body>
<hl style = backgroundcolor:block; fontstyle:
Italic>Hello</h1>
</body>
<html>

Embedded CSS
[1 mark]
Here the style rule for the elementt or the clam all id us spe
specified in the
head element of the page.
Style rule specified will be applied
pplied to every html el
elements on the page.
Example:
<html>
<head>
<style type = text/CSS>
/CSS>
hl
{ background_color:green;
ground_color:gree
ground_color:green;
Font
ont face: Arial
}
</style>
le>
</head>
</html>
External
ternal CSS: Here external stylesheet CSS rule is created and only
contains style
rules.
st
rules
The
Th style rules are applied on every apperance of the elements wherever
oppear
on the web page.
[1 mark]
opp
To link ext
external CSS page on the web page
<html>
<head>
<hea
<such fref= stylesheet.CSS vel = Stylesheet type text/CSS/>
</head>
</html>
6

Prelim Paper Solution

Q.2(c) Explain (i) JIT Compilation (ii) Garbage collection


[5]
(A)
(i) JIT Compilation:
[2 mark]
x JIT complier convert IL to native machine code.
x It only converts that part of code needed at that instant of time
hence the name Just in Time.
x Due to JIT complication we can say C# is two time
e complied
lied
language.

Vi
dy
al
an
ka
r

(ii) Garbage collection:


[2 mark]
x It is a mechanism where memory alloted to
o objectt forwhich no
reference exist is regained automatically.
x It is routine that runs periodically when
when
n the system is free or wh
an allocation does not have sufficient memory.
ry.

Q.2(d) Explain delegate with example.


[5]
(A)
DELEGATE
[3 mark]
class program
{
delegate int MyDelegate
egate (int x, int y);
// d
delegate
static int add (intx,
tx, int
nt y)
{
return (x + y);
);
}
static
c int mul(int x, int y)
{
return (x * y
y);
}
static void main (st
(string [ ] args)
{
MyDelegate md; // Reference of delegate
MyDelegate (add); // function name variable.
md = new
n
MyD
20); // function call
int P = md(10,
md(
Console.WriteLine ("Sum" + P);
Console
MyDeletage md1;
MyD
md1
m = new MyDelegate (mul);
P = md1(20, 40);
Console.WriteLine ("multiplication " + p);
}
}

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Vi
dy
al
an
ka
r

Note :
[2 mark]
x Delegate is a type that enables you to store references to the function.
x Delegates are much like function but with no function body.
x It is declared using delegate keyword.
x The delegate declaration specifies the return type and parameterr list.
x After defining a delegate you can define a variable of delegate
ate type
pe &
can initialize the variable as reference to function.
x We can call the function using delegate variable by passing arguments
ents to it.
Q.3
Attempt the following (any TWO)
Q.3(a) Explain RadioButton and CheckBox control.

(A)

RadioButton
x
x

[10]
[5]
[
[mark]
mar 
mark]

The RadioButton control is used to display


y a radio
io button.
Radiobuttons are used to Select single option
n from multiple optio
options.

Property
AutoPostBack

Description
iption
A Boolean value
ue that specifies
pecifies whether
whethe the
form should
uld be
e posted immediately
immed
after
hecked property has chang
the Checked
changed or not.
aultt is false
Default
Checked
A Boolean
n value that specifies
spec
wh
whether the
radio
o button is checked or
o not.
Id
A unique id for the control
c
GroupName
The name of the group to
t which this radio
button belong
belongs.
OnCheckedChanged
eckedChanged The name of
o the function to be executed
when
whe the Checked
Check property has changed.
Runat
Specifies th
Spec
that the control is a server
control.
Must be set to server
ntro M
Text
The
e te
text next to the radio button
TextAlign
On which side of the radio button the text
should appear (rightor left)

Checkbox contro
control
control is used to display a check box.
x The CheckBox
Check
x Check box
b control is used to select multiple choices.

[2mark]

[ mark]

AutoPostBack
Auto

Specifies whether the form should be posted


immediately after the Checked property has
changed or not.
Default is false
CausesValidation Specifies if a page is validated when a Button

Prelim Paper Solution

Vi
dy
al
an
ka
r

control is clicked
Checked
Specifies whether the check box is checked or
not
InputAttributes Attribute names and values used for the Input [2mark]
element for the CheckBox control
LabelAttributes Attribute names and values used for the Label
el
element for the CheckBox control
Runat
Specifies that the control is a server control..
Must be set to "server"

Q.3(b) Explain Web.Config file.


[5]
(A)
WEB.CONFIG
[2 mark]
ma
The web.config file is an XML based file
le configuration
iguration that co
contains
ations root directory.
directory We can
ca
application wide settings. It is present in applications
lication but we can
c
have only
have more than web.config file for the application
machine.config file.
General form
< Configuration >
< System.web >
< !_Specify compilation,
CustomError_Authentication,
Authorization . />
ilation, CustomError_Authenticat
tomError_Authe
< /System .web
b>
< appsettings
gs >
< !_Specify
Servername,
CustomSettings />
cify file
e path, connection string,
st
S
</ appsettings
psettings >
< /Configuration
Configuration >

for following :
We can
an use web .configuration
.configurat
fo
i) Uses < pages > section
sectio to
t specify whether session or view state is
[1 mark]
enabled
nabled or disabled.
Example
>
< Configuration
Configurat
Co
<S
System .web >
< pages
page enableSessionState = true/ >
</S
</System.web >
</Configuration >

ii) We can use < Custom Errors > to specify Application wide Error
information.
[1 mark]
< Custom Errors mode = On >
9

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

< error Status code = You


redirect = FileUnavailable .aspx/ >
< /custom errors >
iii) Can specify key-value-pair
< appsetttings >
< add key = Key value = Value/ >
< /appsettings >

[1 mark]

Vi
dy
al
an
ka
r

Q.3(c) Explain global.asax.


[5]
5]
(A)
Global.asax
[1 mark]
It is an optional file use to handle application and session
n level events. The
Global.ascx contains code to handle application events that gets trigger
triggered
during start or end of application.
These codes cannot reside in ASP.NET
as it itself are
T page or web services a
not loaded initially. The Global.ascx is use to declare data th
available
that is a
across different application request
est and different
erent browser session.
session
There are two types of Global.ascx
:
bal.a x file in application domain
bal.asc
d
i) Event which gets called
led for every request.
ii) Event which gets invoke under
der certain condi
condition.

For first type of event


ent which occurs in every request are executed in
el :
following model
[2 mark]
ation_ Begin
egin Request ( )
a) Application_
plication_AuthenticateRequest ( )
plication_AuthenticateRequ
b) Application_AuthenticateRequest
plication_Authoriz
()
c) Application_AuthorizeRequest
Application_ResolveRequestCac
lication_ResolveRe
d)) Application_ResolveRequestCache
()
e) ApplicationAcquire_RequestState
ApplicationAcqui
pplicationAc re_Request
_Req
()
f) Application_PreRequest
Application_PreRequestH
Application_PreRequestHandlerExecute ( )
g) Application_PostRequestHanlderExecute
Application_PostRequ
()
h) Application_ReleaseRequestState
Application_
Application_Release
()
i) Application_Upd
pplica
Application_UpdateRequestCache
()
j) Applic
Application_E
Application_EndRequest ( )
For second type
t
that are not fired for every Request :
a)) Application_Start
Appli
b) Se
Session_Start ( )
c) Applilcation_Error ( )
d) Session_End ( )
e) Application_End ( )
f) Application_Disposed ( )

[2 mark]

10

Prelim Paper Solution

Q.3(d) Explain the text box web server control. List and explain any four [5]
text box attributes.
(A)
The TextBox control is used to create a text box where the user can input
text.
[1 mark]
Textbox attributes (properties)
[4mark]
4 mar

Vi
dy
al
an
ka
r

Description
Properties
TextMode The type of text box. SingleLine creates a standard
ard text box,
MultiLine creates a textbox that accepts more
e than one line of
text and Password causes the charaacters that are
re entered to
be masked. The default is SingleLine.
Text
The text content of the text box.
MaxLength The maximum number of characters
erss that can be entered into
i
the text box.
Wrap
Determines whether or nott text wraps automatically when it
reaches the end of a multiline
true.
tiline text
xt box. The default
defau is tru
ReadOnly Determines whether the user
er can change the text in the
textbox. The default
text can be
fault iss False which means
me
te
changed.
Columns
The width of
f the text box in charac
characters. The
Th actual width is
determined
for the text entry.
ed based
ed on the font thats
thats used f
Rows
The height
eight of
f a multi-line text bo
box in lines.
lin
The default value is
0 which
line.
hich sets
ets the height to a single lin

Q.4
Attempt the
he following
wing (any TWO)
TW )
TWO
[10]
Q.4(a) Explain MasterPage
e and steps to create MasterPage.
[5]
(A)
Masterr Page
[2 mark]
x The master page serves
for the other content pages on
serv as a template
t
the
e site.
some code-behind methods, and it could autox The
he master page has so
for the pages and the other tags which are
generate the page titles
tit
each content page.
mentioned in it for e
global page elements that occur on every content
x Maste
Master page stores
sto
page.
e
x Extension: ".Master"
x Content page Stores page-specific elements that are put into the
master.
mast
Extension: ".aspx"
Ex
x Master page code behind can change master page after it acquires
content.
Extension: ".aspx.cs"

11

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Creating Master Pages


[1 mark]
x Open the application and add new Item and select Master Page.
x Write any code between the <form>tag of the master page.
x It has two <ContentPlaceHolder>tags , one in the <head> and other in the
<body> part of the page.
The code looks like this

Vi
dy
al
an
ka
r

<%@MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.mas
MasterPage.mas
e.mas
ter.cs"Inherits="MasterPage"%>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
ver">
er">
</asp:ContentPlaceHolder>
</head>
<body>
<formid="form1"runat="server">
[2 mark]
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1"
ntentPlaceHolder1"
Holder1" runat="server">
runat="serve
runat=
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

Any element added to the master page outside


outsid the contentplaceholder will
appear on every content
ntent page that
at use
uses the master page.

Q.4(b) Whatt is State management? Explain session in ASP.NET?


[5]
(A)
State
[2 mark]
tate management
ASP.NET
NET is based on state
stateless http protocol so every request from client
browsed to web server is an iindependent request is understood as.
State management it a tec
technique used to maintain the state information for
multiple requests.
asp.net
p.net pages cro
cross mul
with built in support for state management both at client
Asp.Net comes
c
side and serves
se
sside.
state
Ses
Session
sta
duration of communication between client and browses. Session into is
It is dur
stored per use per session.
store
Session into can be saved in session object at server side.
Se
To specify whether or not to use cookie to stare session info
In web.config
[1 mark]
<sessionstate cookieless = true/false/>
12

Prelim Paper Solution

[1 mark]
[1 mark]

Vi
dy
al
an
ka
r

To specify the session storage mode


<sessionstate mode = Inprove/stateserver/salserver/>
To enable or disable session
Session can be enabled as disabled at
(1) Page level
in .aspx
<%Page enableSessionstate = true/false />
(2) Application level
in web.config
<pages enable.Sessionstate = true/false/>

Q.4(c) Explain two navigation controls.


[5]
(A)
Two Navigations Control
Navigation controls provided by ASP.net. ASP.Net
Net provides following
followin three
thre
navigations control.
i) Treeview
ii) Menu
iii) SiteMapPath
SiteMapP
i)

Treeview
[2
[
marks]
It arranges the pages in hierarchical
chical mannew. The
Th pages are organized
to form a tree structure.
e.

Steps to use treeview


iew control
ontrol
Since tree view control cannot fetch infor
information directly from sitemap
file hence it needs SiteMapDataSour
SiteMapDataSource.
Drag and drop
rop SiteMapDataSource
MapDataSource fr
from
tool box
information from SiteMap
x o Data.
ata. It automatically
automatical fetches
fetc
file.
Drag
rag
ag and drop treeview from
toolbox
box o navigation
In treeviewt
treeviewtask o In c
choose datasource select SiteMapData Source
Save it Run it.

ii) Menu
[2 marks]
pages in menoform or it creates menu of pages.
It arranges the pag

Step tto use Me


Menu Control
Since menu view control cannot fetch information directly from sitemap
file hence it needs SiteMapDataSource.
Drag and drop SiteMapDataSource form toolbox o Data. It
automatically
fetches information from SiteMap file.
aut
Drag and drop Menu from
tool-box o navigation

In Menu task o In choose datasource Select SiteMapDataSource


Save it Run it.
13

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Q.4(d) Explain Validation controls.


[5]
(A)
Validation control in ASP.Net
ASP.Net provides various validation controls to validate the content of the
other controls whose value will be specified by the user.

Vi
dy
al
an
ka
r

ASP.Net provides following validation controls


i) Compare validator
ii) Custom validator
iii) Range validator
iv) Regular Expression Validator
v) Required field validator
vi) Validation summary
i)

Compare validation
General form
< asp : Compare Validator ID = CompareValidator1
CompareValidator1
eValidator1
runnat = Server ErrorMessage
age = CompareValidator>
CompareValidator>
< / asp : CompareValidator >

[ mark
[1
mark]

It validates the content


comparing us value with
ontent
nt of a control by compar
preexisting value or value of
f other control.

ii) Custom Validator


[1 mark]
idator
General form
< asp : CustomValidator
CustomValidator
1
Validator ID = C
CustomVa
runnat
nnat = Server ErrorMessage
ErrorMessa = CustomValidator>
C
</asp : CustomValidator >

Itt validates the content


conten of tthe control using Logic specified by the user
orr customised logic
lo

iii)) Range Validator


[1 mark]
Valida
General
Genera form
ID = RangeValidator 1
< asp : RangeValidator
RangeV
runnat = S
Server ErrorMessage = Rang Validator> </asp : RangeValidator
>
validate the content of the control by ensuring that the value falls
It va
within the specified range.
w
iv) RegularExpressionValidator
General form

[1 mark]

14

Prelim Paper Solution

< asp : RegularExpressionValidator ID = RegularExpressionValidator


runnat = Server ErrorMessage = RegularExpressionValidator>
</asp : RegularExpressionValidator >
It validates the content of the control by ensuring that the expression
ress
mathches the pre-specified pattern.
[1 mark
mark]

Vi
dy
al
an
ka
r

v) RequriedFieldValidator
General form
< asp : RequiredFieldValidator ID = RequiredFieldValidator
idator
runnat = Server ErrorMessage = RequiredFieldValidator>
alidator>
</asp : RequiredFieldValidator >

It validates the content of the control by ensuring


nsuring that the control
con
should not be empty.

Q.5
Attempt the following (any TWO)
Q.5(a) Explain ADO.NET architecture.
(A)
ADO.NET ARCHITECTURES

[10]
[5]
[2 mark]

1) DataSet : ADO.Net can work in connected as well as in disconnected


mode. DataSet is core component of disconnected architecture.
It is in memory representation of db it can be used to cache data locally
& can track changes to the data.
[ mark]
e.g. : DataSet ds = new DataSet (customers);
2) DataTable : A DataTable is use to represent a table in a database. It
consist of collection of rows & columns.
[ mark]
15

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

3) DataView : It provide customized view of the data Table. It can be


used as sort of filters for rows of DataSet.
e.g.:
DataView dv = cust.Tables[Reliance]
DefaultView;
dv.RowFilter = Address like Hyderabad

Vi
dy
al
an
ka
r

an use
us
4) DataProvider : DataProvider provides access to the db.. We can
Oracle, SQL server, OLEDB as data proviers.
[2 mark]
ark]
The DataProvider classes includes :
(a) Connection
(b) Command
(c) Data reader
(d) Data Adapter
dapte

(a) Connection Object : It is use to establish


we
sh connection to th
the db w
can use OleDB connection, odbc connection, Orac
OracleConnection,
OracleConnec
SQLConnection.

(b) Command Object : It is use


Query to the
e to send SQL Q
th db. we can
use OracleCommand,
d,, SqlCommand, etc.
The CommandObject
ject makes use of :
1) ExecuteScalar
value from query.
calar : Returns
urns a single val
2) ExecuteReader
of rows & columns as
eReader
er : Returns collection
colle
resultSet.
et.
3) ExecuteNonQuery
insert,
delete, update and returns
eNonQuery : Rerform
Rerfo
inse
of rows affected by operation.
integer representing number
nu
Returns xmlReader Obj as result of query.
4) Execute XMLReader : Return

connected, forward, read-only, stream of Data i.e.


(c) DataReader : It is connect
of record from db.
use to read sequential
sequent collection
c
It is faster than DataSet but requires open connection. The
DataReader we can
DataReade
ca use are : OracleDataReader, SqlDataReader, etc.

DataAdapter : It is use in disconnected mode of DataAccess. It acts as


(d)) DataAdapte
Dat
a bridge between Db & DataSet & it populates the data with the data
from db.
The DataAdapter provides 2 methods :
Th
(i) Fill
(ii) Update
Fill : The fill method will populate dataset with value from db.
Update : Update method is use to commit changes back to the db.

16

Prelim Paper Solution

Vi
dy
al
an
ka
r

Q.5(b) Write a program to retrieve data from Table in connected Mode.


[5]
(A)
Using System;
Using System.Data.SqlClient;
Using System.Data;
[1 Ma
Mark]
Class Program
{
PSVM(String[ ] args)
{
SqlConnection con = new SqlConnection();
[2 Mark]
SqlCommand cmd = new SqlCommand();
);
con.ConnectionString = DataSource = (local);
InitialCatalog : Student; UserID = sa;
Password = sa; ProviderName = System.Data.SqlClient;
stem.Data.SqlClient;
SqlClient;
try
{

con.open();
ert into student (n
cmd.CommandTextt = insert
(name, num
number of KT)
C,, 5);
5)
values (ABC,
cmd.Connection
tion = Con;
[2 Mark]
cmd.ExecuteNonQuery();
cuteNonQuery();
nQuery();

}
Exception
n e) { }
catch(Exception
finally
lly {con.Close
.Close ( ); }

Q.5(c) Explain
ASP.NET.
n security concepts in ASP.
(A)
ASP.NET
NET SECURITY
SECURI
(b) Authorization.
(a) Authentication

[5]

(c) Impersonation.

(a)
a) Authentication
Authenticatio
[2 mark]
(i)
i) W
Window mode : (Default) done by IIS.
mode
(ii) Form
For
mod : The data is obtained using HTML form & the
Authentication rule is specified by user itself.
Authen
Mode : Microsoft provides passport based authentication
(iii) Passport
Pass
when user sign up for the passport then the authentication it is
w
stored at Microsoft server.
[2 mark]
(b) Authorization
(i) File Based : Here the access specification is provided in a file called
ACL (access control list) the privilege of user is identified by the
list.
17

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Vi
dy
al
an
ka
r

(ii) URL Based : Here the authorization specification is done in


web.config file.
<authorization>
<[allow/deny] user role>
</authorization>
rk]
(c) Impersonation
[1 mark]
nd the acces
access
Here the process identifies itself as a legitimate user and
the Resource. specified in <identify> section of web.config
onfig file
<configuration>
<configuration>
<identity impersonate = false>
</configuration>
Here impersonate = false means impersonation
nation is not supported.

ntrols in ASP.NET.
Q.5(d) Explain the various Data Source controls
[5]
(A)
DATA SOURCE CONTROLS IN ASP.NET
DataSource provide efficient, flexible
ble & extensible
extensib storage for data in
ASP.Net
The various DataSourceControls
Controls
rols are :
1) Access DataSource
[1 mark]
ce Control :
It is used to connect
using MS-office.
onnect to A
Access
ccess DB created
creat usin
Syntax : <asp
AccessDataSource1 runat =
sp : Access
ess DataSecure id = Acce
server>
</asp>
sp>
2) SQLDataSource
QLDataSource control
cont
:
[1 mark]
It iss used to connect to
t sql db ssupported by ADO.Net.
<asp:SqlDataSource
id = SqlDataSource1 runat = server>
Syntax
yntax : <asp:SqlDataSou
<asp:SqlData
</asp
</asp>
3)) LinqDataSource
LinqDataSour Control
Con
:
[1 mark]
connect to collections of object from the application.
It is used
u
to conn

4) EntityDataSource
EntityDataS
contend :
[1 mark]
used to connect to dataSource in EntityDataModel supported by
It is use
.Net framework.
f
5) X
XMLDataSource Control :
It is used to connect to XML.

[ mark]

6) ObjectDataSource Control :
It is used to bind data from Generic object to data controls.

[ mark]

18

Prelim Paper Solution

Vi
dy
al
an
ka
r

Q.6
Attempt the following (any TWO)
[10]
Q.6(a) Explain AJAX server control.
[5]
(A)
ASP.NET AJAX server control
A) Update Panel Control
[2 mark]
The update Panel control is most important control for creating flicke
flickerfree pages we just rap the control around the content that we wantt to
update and add the script manager to the page.
Properties
i) Childrens Triggers : This property determine
e whether
ther controls
located within update panel will cause refresh of the update
pdate panel.
ii) Triggers : The trigger collection containss PostBack
Back Triggers and
AsyncPostBack Trigger.
PostBack Trigger is used when we want to force complete page
refresh.
AsyncPostBack Trigger is used when you want to upda
update
update on up
panel.
iii) Render Mode : The properly
Block indicate
erly can be set to Inline or Bloc
whether this update panel renders itself as <div>
element or span
<div> elem
element.
iv) Update Mode : Itt determine
is
termine whether the control
c
i always refreshed
(set to always)) or underss certain conditi
condition (Trig
(Triggers).
B) ScriptManager
[1 mark]
nager Control
ntrol
ScriptManager
client page and server. It
Manager acts as a bridge between
betwe
makes
ASP.NET AJAX files are included and
es source that
hat the require
required ASP
AJAX
JAX support is added. It must be included on every page where we
wish to add AJAX functionality.
fun
=UpdatePanel
<asp : UpdatePanel
UpdatePanel ID
I =U
server>
runat = se
UpdatePanel>
</asp : UpdatePane
ScriptManager ID = ScriptManager1
<asp : ScriptMan
Scr
runat = server>
ru
</asp : ScriptManager>
</a
Scr

C) UpdateProgress
UpdatePr
Control
[1 mark]
Even though there was visual problem in postback but it has one
advantage
that user can see something is happening however with update
adv
panel user will have no idea that something is happening until it has
happened.
To tell user to wait for few seconds while their request is processed, we
can use update progress control.
19

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Properties
i) DisplayAfter : It determines the time in milliseconds that the
control has to wait before it displays its content.

Vi
dy
al
an
ka
r

D) TimerControl
[1 ma
mark]
The timercontrol is use for executing server side code on repetitive
tive
basis.
e.g. we can use it to update the content of update panel
el after every
very 5
seconds

Q.6(b) Explain LINQ operators.


(A)
Operators in LINQ are as follows
Type
Aggregation

Conversion

Element

Equality
Generation
ration
n
Group
roup
Joining
Ordering
Portioning

Quantifying
Restriction
Restri
Selection
Set
S
et

[5]

Operators
Average
Count
Max
MIN
SUM
Cast
To Array
rray
To
o Dictionary
To Sequence
equence
Element
men At
first
last
ast
Equal
Equals
Range
Group By
Join
J
Order B
By Ascending Order By Descending.
Skip
Tak
Ta
All
Any
Where
Select
ConCat
Distinct
InterSect
Union

20

Prelim Paper Solution

Vi
dy
al
an
ka
r

Q.6(c) Explain Jquery and advantages.


[5]
(A)
JQUERY
[3 mark]
x To overcome the disadvantage of JavaScript we use JQuery.
x Initially developed by John Resign in 2006. It became very popular
clientside framework and Microsoft has started shipping the Microsoft
icroso
product with JQuery.
x The main focus of JQuery Library is to simplify the way we access
ss th
the
element in our webpage.
x It provide helps in working with clientside events, enable
nable visual effects
like animation and makes it easy to use AJAX in over
er application.
ation.
x We can download the latest version of JQuery
Query from site
http://jquery.com
x Beside down loading the library from jquery
uery website, any new website
we
that is created using ASP.NET website
folder
e template
plate contains script
scripts folde
with necessary JQuery files.
x JQuery increases the size of your
our webpage
page and hence it is
i a deliberate
del
choice to include it on your page
age or not.
x JQuery helps the program to keep
conside.
ep the code simple and cons
x JQuery library is design
revisable.
n to keep the thing simple and
a rev
x JQuery simplifies the
html DOM
he process
rocess of
f traversal of h
DO tree.
x It has following features
eatures :
i) Supports the
he event
ent
ii) Supportt AJAX
[2 mark]
iii) Better
er effects
ects and animations
iv) DOM
function
OM element
ent selection fun
v) Support for CSS
modification
vi) DOM traversal and
an modificat

Q.6(d)
d) Explain any
a five methods of
o J
Jquery.
[5]
(A))
[Any Ten Five Mark]
JQUERY EFFECT METHOD
improves look and feel of website, at client side.
x These methods
method impro
to use and are
x These are easy
e
1) ani
animate( ) : It performs the specified animation for the element.
ClearQueue( ) : To remove all queued function for the element.
2) ClearQu
3) delay(
delay ) : To set delay for all queued function for the element.
fade In( ) : It changes the opacity of the element from hidden to
4) fad
visible.
5) fade Out( ) : It changes the opacity of the element from visible to
hidden.
6) hide( ) : It hides the specified element.
7) fade To( ) : It changes the opacity of the element to specified value.
21

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

Vi
dy
al
an
ka
r

8) show( ) : It displays the hidden elements.


9) slide Up( ) : It slowly changes the hide of the element from visible to
hidden.
10) slide Down( ) : It slowly changes the hide of the element from hidden
to visible.
11) slide Toggle( ) : This method toggles between SlideUp and SlideDown
own
of the element.
12) stop( ) : Stop the animation of selected element.
13) Toggle : This method toggles between hide and show
how method
ethod for the
element.

Q.7
Attempt the following (any THREE)
[
[10]
Q.7(a) What is method overloading? Explain with example.
e
[5]
(A)
Method overloading provides the programmer
create
mmer with the capability to creat
multiple methods with the same name,
different
e, but each working with
w
diffe
parameters.
[2 mark]
[3mark]

Example:
class abc
{

public void Disp(int


sp(int
nt a)

Console.WriteLine(a);
e.WriteLine(a);

public
lic void Disp(int a, int b)

Console.WriteLine("{0}{1}",
a,b);
Console.WriteLin
Console.WriteLine("{0}{1}

}
class
ss Program
ogram
{
staticvoid
taticvoid Main(string[]
Main(s
Main(string args)
{
abc a1 = ne
newabc();
a1.Disp
a1
((10);
a1.Disp
a1.Dis (10,20);
}
}

[5]
Q.7(b)
of assembly in .Net Framework.
b) Purpose
Pur
(A)
A)
The pur
purpose of assembly in .Net Framework:
[2mark]
x Assemblies
in .Net are a solution to the Dll hell problem as one can use
A
different versions of same assembly in different applications at the
same time

22

Prelim Paper Solution

Assemblies are designed to simplify application deployment and to solve


versioning problems that can occur with component-based applications.

Vi
dy
al
an
ka
r

To solve versioning problems, as well as the remaining problems that lead to


DLL conflicts, the runtime uses assemblies to do the following:
[3 ma
mark]
x Enable developers to specify version rules between different softwar
software
ar
components.
x Provide the infrastructure to enforce versioning rules.
x Provide the infrastructure to allow multiple versions of a component
omponent to
be run simultaneously (called side-by-side execution).
).
x simplify uninstalling and replicating applications.

Q.7(c) What are the uses of AutoPostBack and runat


at properties?
[5]
(A)
x The AutoPostBack property is used to set or return
turn whether or not an
automatic post back occurs
when the user
ser selects an item in a llist
control.
x If this property is set to TRUE the automatic post back is enabled,
otherwise FALSE. Default is FALSE.
E.
x Syntax
<asp:SomeListControl AutoPostBack="TRUE|FALSE"
utoPostBack="TRUE|FA
runat="server"/>
run
[2 mark]
Example:
[3 mark]
The following example
property to "True" for a
xample sets the AutoPo
AutoPostBack p
RadioButtonList
st control:
ol:
<script runat="server">
rver">
Sub Change(obj As Object, e As EventArgs)
E
Response.Write("You
onse.Write("You selected " & rb1.SelectedItem.Text)
End Sub
</script>
pt>
<form
form runat=server>
<asp:RadioButtonList id="rb1" AutoPostBack="True"
<asp:RadioButtonL
runat="server"
at="server" OnSelectedIndexChanged="Change">
<asp:ListItem Text="Item 1" />
<asp:ListI
<<asp:ListItem Text="Item 2" />
</asp:RadioButtonList>
</as
</form>
</f

Runat
Runat:
Runat='Server' Indicates the accessibility of the control at Serverside.
Ru
If runat="server" is placed inside any of the control then that control cab

23

Vidyalankar : T.Y. B.Sc. (IT) ASP.NET

be used at the server side.


e.g
<asp:TextBox id="txt" Runat="Server"></asp:TextBox>

Vi
dy
al
an
ka
r

Q.7(d) List the different places in the web application where ViewState
ate [5]
field can be disabled?
(A)
Viewstate can be disabled at the following places in the web application.
plication.
n.
1. Page
2. Control
3. Application
4. Machine
ne
[2 mark]
ark]
Page
<% @Page.EnableViewState=false/>
Control
<asp : TextBox id=Name runat=server EnableViewState=false/>
eViewState=false/>
ewState=false/>
For Application
< Page enableViewState = false /?

[[3
3 mark
mark]

For Machine
<Page enableViewState=false enableViewStateMac=false
ableViewStateMac=false
ateMac=false />

Q.7(e) Explain the term authentication


[5]
catio with
cation
th respect to AS
ASP.NET security.
(A)
The Term authentication
[2mark]
n with
ith re
respect
pect to ASP.NE
ASP.NET security
secu

x Authentication is the process
ss of obtaining id
identification credentials such
as name and password
ord from a user and
an validating those credentials
against some authority.
rity
x If the credentials
ials are valid, the entity
e
that submitted the credentials is
considered an authenticated identity.
id
There are three ways of doing authentication
a
and authorization in ASP.NET:
x Windows
dows authenticati
authentication
[1mark]
In
n this methodology ASP.NET
AS
web pages will use local windows users and
groups
roups to authenticate and
a authorize resources.
x Forms
orms Authentication
[1mark]
This is a coo
cookie based authentication where username and password are
stored on client machines as cookie files or they are sent through URL for
every
ry rrequest. Form-based authentication presents the user with an HTMLbased Web page that prompts the user for credentials.
x Passport authentication
[1mark]
Passport authentication is based on the passport website provided by
the Microsoft .So when user logins with credentials it will be reached to
the passport website (i.e. hotmail, devhood, windows live etc) where
authentication will happen. If Authentication is successful it will return
token to your website.

24

Prelim Paper Solution

Vi
dy
al
an
ka
r

Q.7(f) What is the use of Document Ready Event and explain with [5]
example.
(A)
Document.Ready():
[3mark]
x It is used to prevent any JQuery code from running before the
document is finished loading because there are few functions which
can
hich c
fail if they run before the document is loaded.
x General form$(document).ready(function( )
{
} );
Example :
<html>
<head runat=server>
<script type=text/JavaScript src=jquery.js>
uery.js>
>
$(document).ready(function()
{
$(button).click (function()
unction()
n()
{
$( table).hide();
table).hide();
e).hide();
});
});
</script>
</head>
<body runat=server>
at=server>
r>
<table
e border=1>
border
2</td> <td> 3</td> <td> 4</td>
<tr> <td> 1</td
1</td> <td> 2</td
</tr>
</t
</table>
<input type=button value=Hide/>
value=
</body>
</html>
tml>

[2mark]
[2 mark]
mar

25