Sei sulla pagina 1di 25

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

V
ASP.NET with C#
Time : 2 ½ Hrs.] Prelim Question Paper Solution [Marks : 75

Q.1 Attempt the following (any TWO) [10]


[10
Q.1(a) Write a program to find reverse of number. [5
[5]
(A) Program
using System;

r
using System.Collections.Generic;
using System.Linq;

ka
using System.Text;

namespace palindrome
{
class program
{
an {
static void Main (String args [ ])

int n, r, d = 0, n1;
1;
Console.WriteLine("Enter
riteLine("Enter
"Enter the no :");
[1 mark]
n = Convert.ToInt32(Console.ReadLine(
vert.ToInt32(Console.ReadLine(
oInt32(Console.ReadL ));
))
n = n1;
1;
al
n1 ! = 0)
while (n1 0
{
r = n1%10
n1%10; [3 mark]
dy

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 [1 mark]
Vi

else
Console.WriteLine(n + is not palindrome);
Co
}
}
}

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

Q.1(b) Explain out parameter. [5]


(A) Out Parameter
Out parameter works similar to ref. parameter however it has following
differences [1 mark]
(i) It is illegal to used unassigned variable as ref parameter. [1 mar
mark]
(ii) An out parameter must be treated as unassigned value by the he function
tion
that uses it. [1 mark
mark]
namespace NP1
{ [2 mark]
class P1

ka
{
static void main (string [ ]args)
{
int a = {11, 12, 13, 14, 15};
int p; // unassigned variable. ble.
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;
}
}
}

2
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++.

The runtime problem causes abnormal termination of program


rogram
m however in

r
java/C#.

ka
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 occurrence of
onitored for occur
exception.
an It exception is generated in try block ck there is chance
cha of it being
handled. When exception is generated
ated outside the try block, it
i cannot be
handled and causes abnormal
mal program
ogram termination. [1 mark]

ii) catch block


It contains exception
ption handling code.
code. [1 mark]
al
iii) throw
It is used
sed to manually throw an ex
exception
cept normally used for throwing
user-defined
-defined exception.
xception. [1 mark]

iv)) finally
ly
dy

It contains code that must


m be
b executed whether exception is generated
orr not or generated exce
exception is handled or not it is executed before
ex
method
ethod returns to its caller.
c [1 mark]

Q.1(d)
1(d) Explain CLR.
CL [5]
Vi

(A) CLR (COMMON


(COM LANGUAGE
L RUNTIME) [2 mark]
of the most essential components of .net framework.
x CLR is one o
x CLR is the
t environment where all programs using .net technologies over
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

x 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.
x 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).
x The CLS enables an object or application to interact with the bjects ects o
or
application of other language.
x The classes that follows the rules specified by CLS are termed ermed as CLS

r
compliant classes.

ka
x One of the specification defined in CLS is Common mon Typed
ped System (CTS).
x CTS provides a type system that is common acrosscross all languages.
x CTS defines rules that ensure that the data object written in va various
languages are able to interact with each h other.
r.
x During execution CLR performs following
owing steps
teps :
an (a) Loading assemblies & identifiesfies name
me spaces [1 mark]
x assemblies are loaded d into memory after loadin assemblies the
loading assem
CLR will identifies namespace
pace for the code in assemblies.
assemb
x namespaces are e collections of classes (similar
(s package
p in java)
namespaces are used to organised the classes
c in hierarchy.
x The namespaces
spaces have
ve public access
access & this ccan not be change.

(b) JIT Compilationn (Just-in-time)


mpilation [1 mark]
al
Before
re execution converted into machine language using
ecution the IL is converte
c
JIT complier.
mpli
The IL code is examined for following points :
f foll
x The memory location
l that code needs to access are available.
dy

x methods are called


ca only
onl through properly define types
x IL correctly generated.
L has been cor
correct

(c) Garbage CCollection


Collectio [1 mark]
x The garbage
garbag collection process begins after the JIT compilation.
manages the allocation & de-allocation of memory for an
x It man
Vi

application.
appli
x WWhen you create an object the CLR allocates memory for the
object from managed heap.

4
Prelim Paper Solution

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

r
i) Page_Render j) Page_Unload
e_Unload

ka
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
anIt restores the pages view state information
formation
n from its last saved
s state.
stat

Load Post Back Data [1 mark]


It populates the server control
trol in your
tro our web with the posted
p data.
d

PageLoad [1 mark]
It restores the control
ntrol the
he values of
o the web
w page
pag i.e. the data will be
binded to the data
a controls.
rols.
al
Page-PreRender nder [1 mark]
It is calledd prior to the rendering
ndering of
o page event
ev here we can add code to make
changes
ess in the rendered output.
dy

Save
ave View w State [1 mark]
It is responsible for saving view state information of web page.

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

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

Q.2(b)) Explain
Ex CSS & its types. [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 It separates presentation from data.


x 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

Example [1½ mark]

r
<html>

ka
<body>
<hl style = “backgroundcolor:block; fontstyle:
Italic>Hello</h1>
</body>
<html>
an Embedded CSS
Here the style rule for the elementt or the clam all id us spe
head element of the page.
Style rule specified will be applied
pplied to every html el
[1½ mark]
specified in the

elements on the page.


Example:
<html>
<head>
al
<style type = “text/CSS”>
/CSS”>
hl
{ background_color:green;
ground_color:gree
ground_color:green;
Font
ont face: Arial
dy

}
</style>
le>
</head>
</html>
External
ternal CSS: Here external stylesheet CSS rule is created and only
contains style
st rules.
rules
Vi

The
Th style rules are applied on every apperance of the elements wherever
oppear
opp on the web page. [1½ mark]
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.

(ii) Garbage collection: [2½ mark]

r
x It is a mechanism where memory alloted to o objectt forwhich no

ka
reference exist is regained automatically.
x It is routine that runs periodically whenn the system is free or wh
when
an allocation does not have sufficient memory.
ry.

Q.2(d) Explain delegate with example. [5]


(A) anDELEGATE [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);
);
}
al
static
c int mul(int x, int y)
{
return (x * yy);
}
dy

(string [ ] args)
static void main (st
{
MyDelegate md; // Reference of delegate
md = new
n MyDelegate (add); // function name variable.
MyD
int P = md(10,
md( 20); // function call
Console.WriteLine ("Sum" + P);
Console
Vi

MyDeletage md1;
MyD
md1
m = new MyDelegate (mul);
P = md1(20, 40);
Console.WriteLine ("multiplication " + p);
}
}

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

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.

r
Q.3 Attempt the following (any TWO) [10]

ka
Q.3(a) Explain RadioButton and CheckBox control. [5]
(A) RadioButton              [½
[½mark]
mar 
mark]
x The RadioButton control is used to display
y a radio
io button.
x Radiobuttons are used to Select single option
n from multiple optio
options.

Property Description
iption
AutoPostBack A Boolean value ue that specifies
pecifies whether
whethe the
an form should uld bee posted immediately
immed
hecked property has chang
the Checked
aultt is false
Default
after
changed or not.

Checked A Boolean n value that specifies


spec wh
whether the
radio
o button is checked oro not.
Id A unique id for the control
c
al
GroupName The name of the group to t which this radio [2mark]
button belong
belongs.
OnCheckedChanged
eckedChanged The name of o the function to be executed
when
whe the Checked
Check property has changed.
dy

Runat Specifies th
Spec that the control is a server
control.
ntro M Must be set to “server”
Text The
e te
text next to the radio button
TextAlign On which side of the radio button the text
should appear (rightor left)
Vi

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

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

8
Prelim Paper Solution

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 Labelel
element for the CheckBox control
Runat Specifies that the control is a server control..

r
Must be set to "server"

ka
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 cocontains
ations root directory.
application wide settings. It is present in applications directory We can
ca
lication but we can
have more than web.config file for the application c have only
anmachine.config file.

General form
< Configuration >
< System.web >
< !_Specify compilation, CustomError_Authentication,
ilation, CustomError_Authenticat
tomError_Authe Authorization . />
< /System .web b>
al
< appsettings
gs >
< !_Specify
cify file
e path, connection string,
st Servername,
S CustomSettings />
</ appsettings
psettings >
< /Configuration
Configuration >
dy

We can
an use web .configuration
.configurat for following :
fo
i) Uses < pages > section
sectio to
t specify whether session or view state is
nabled or disabled.
enabled [1 mark]

Example
< Configuration
Configurat
Co >
Vi

<SSystem .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 [1 mark]
< appsetttings >
< add key = “Key” value = “Value”/ >
< /appsettings >

Q.3(c) Explain global.asax. [5]


5]

r
(A) Global.asax [1 mark]

ka
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 T page or web services a


as it itself are
an 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
al
following modelel : [2 mark]
ation_ Begin
a) Application_ egin Request ( )
plication_AuthenticateRequest ( )
plication_AuthenticateRequ
b) Application_AuthenticateRequest
c) Application_AuthorizeRequest
plication_Authoriz ()
dy

d)) Application_ResolveRequestCache
Application_ResolveRequestCac
lication_ResolveRe ()
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 ()
Vi

j) Applic
Application_E
Application_EndRequest ( )

For second type


t that are not fired for every Request : [2 mark]
a)) Application_Start
Appli
b) Se
Session_Start ( )
c) Applilcation_Error ( )
d) Session_End ( )
e) Application_End ( )
f) Application_Disposed ( )

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
Properties Description
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

r
text and Password causes the charaacters that are re entered to
be masked. The default is SingleLine.

ka
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
tiline text
xt box. The default true.
defau is tru
an ReadOnly Determines whether the user er can change the text in the
textbox. The default
fault iss False which means me text can be
te
changed.
Columns The width of f the text box in charac
characters. The
Th actual width is
determined
ed based
ed on the font that’s
that’s used ffor the text entry.
Rows The height
eight of
f a multi-line text bo
box in lines.
lin The default value is
0 which
hich sets line.
ets the height to a single lin
al
Q.4 Attempt thehe following
wing (any TWO)
TW )
TWO [10]
Q.4(a) Explain MasterPage e and steps to create MasterPage. [5]
(A) Masterr Page [2 mark]
dy

x The master page serves


serv as a template
t for the other content pages on
thee site.
x Thehe master page has so some code-behind methods, and it could auto-
generate the page titles
tit for the pages and the other tags which are
mentioned in it for e each content page.
Master page stores
x Maste sto global page elements that occur on every content
Vi

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

<%@MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.mas
MasterPage.mas
e.mas
ter.cs"Inherits="MasterPage"%>

r
<html>
<head runat="server">

ka
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
ver">
er">
</asp:ContentPlaceHolder>
</head>
<body>
<formid="form1"runat="server"> [2 mark]
an <div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1"
Holder1" runat="server">
ntentPlaceHolder1" runat="serve
runat=

</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
al
Any element added to the master page outside
outsid the contentplaceholder will
appear on every content
ntent page that uses the master page.
at use

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


dy

(A) State
tate management [2 mark]
ASP.NET stateless http protocol so every request from client
NET is based on state
browsed to web server is an iindependent request is understood as.
State management it a tectechnique used to maintain the state information for
asp.net
p.net pages cro multiple requests.
cross mul
Asp.Net comes
c with built in support for state management both at client
Vi

side and serves


se sside.

Ses
Session state
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

To specify the session storage mode [1 mark]


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

r
<pages enable.Sessionstate = “true/false”/>

ka
Q.4(c) Explain two navigation controls. [5]
(A) Two Navigations Control
Navigation controls provided by ASP.net. ASP.Net followin three
Net provides following thre
navigations control.
ani) 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 treeviewiew control
ontrol
Since tree view control cannot fetch infor
information directly from sitemap
file hence it needs SiteMapDataSour
SiteMapDataSource.
al
Drag and drop
rop SiteMapDataSource
MapDataSource frfrom
tool box ata. It automatically
x o Data. automatical fetches
fetc information from SiteMap
file.
Drag
rag
ag and drop treeview from
box o navigation
toolbox
dy

treeviewtask o In c
In treeviewt 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
Vi

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
aut fetches information from SiteMap file.
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.

ASP.Net provides following validation controls


i) Compare validator
ii) Custom validator
iii) Range validator

r
iv) Regular Expression Validator

ka
v) Required field validator
vi) Validation summary

i) Compare validation [ mark


[1 mark]
General form
an < asp : Compare Validator ID = “CompareValidator1”
CompareValidator1”
eValidator1”
runnat = “Server” ErrorMessage
age = “CompareValidator”>
CompareValidator”>
< / asp : CompareValidator >

It validates the content


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

ii) Custom Validator


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

Itt validates the content


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

iii)) Range Validator


Valida [1 mark]
General
Genera form
Vi

< asp : RangeValidator


RangeV ID = “RangeValidator 1”
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 [1 mark]


General form

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.

v) RequriedFieldValidator [1 mark
mark]
General form

r
< asp : RequiredFieldValidator ID = “RequiredFieldValidator”
idator”
runnat = “Server” ErrorMessage = “RequiredFieldValidator”>
alidator”>

ka
</asp : RequiredFieldValidator >

It validates the content of the control by ensuring


nsuring that the control
con
should not be empty.

Q.5 anAttempt the following (any TWO) [10]


Q.5(a) Explain ADO.NET architecture. [5]
(A) ADO.NET ARCHITECTURES [2 mark]
al
dy
Vi

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’”

4) DataProvider : DataProvider provides access to the db.. We can


an use
us
Oracle, SQL server, OLEDB as data proviers. [2 mark]
ark]

r
The DataProvider classes includes :

ka
(a) Connection (b) Command
(c) Data reader (d) Data Adapter
dapte

(a) Connection Object : It is use to establish


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

(b) Command Object : It is use e to send SQL Q Query to the


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

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


(c) DataReader : It is connect
use to read sequential
sequent collection
c of record from db.
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
Vi

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

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();

r
[2 Mark]
SqlCommand cmd = new SqlCommand();

ka
)”;
con.ConnectionString = “DataSource = (local)”;
InitialCatalog : Student; UserID = sa;

Password = sa; ProviderName = “System.Data.SqlClient”;


stem.Data.SqlClient”;
SqlClient”;

try
an {
con.open();
cmd.CommandTextt = “insertert into student (n
(name, num
number of KT)
C’,’, 5)”;
values (‘ABC’, 5)”
cmd.Connection
tion = Con;
cmd.ExecuteNonQuery();
cuteNonQuery();
nQuery(); [2 Mark]
}
al
Exception
catch(Exception n e) { }
finally
lly {con.Close
.Close ( ); }
}
}
dy

Q.5(c) Explain ASP.NET.


n security concepts in ASP. [5]
(A) ASP.NET
NET SECURITY
SECURI
(a) Authentication (b) Authorization. (c) Impersonation.
(a)
a) Authentication
Authenticatio [2 mark]
(i)
i) W Window mode : (Default) done by IIS.
Vi

(ii) Form
For mode
mod : The data is obtained using HTML form & the
Authentication rule is specified by user itself.
Authen
(iii) Passport
Pass Mode : Microsoft provides passport based authentication
when user sign up for the passport then the authentication it is
w
stored at Microsoft server.
(b) Authorization [2 mark]
(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

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


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

r
<configuration>

ka
<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
anDataSource provide efficient, flexible
ASP.Net
The various DataSourceControls
Controls
rols are :
extensib storage for data in
ble & extensible

1) Access DataSource ce Control : [1 mark]


It is used to connect
onnect to A
Access
ccess DB created using MS-office.
creat usin
al
Syntax : <asp
sp : Access “AccessDataSource1” runat =
ess DataSecure id = “Acce
“server”>
</asp>
sp>

2) SQLDataSource
QLDataSource control
cont : [1 mark]
dy

t sql db ssupported by ADO.Net.


It iss used to connect to
Syntax <asp:SqlDataSource
yntax : <asp:SqlDataSou
<asp:SqlData id = “SqlDataSource1” runat = “server”>
</asp
</asp>

3)) LinqDataSource
LinqDataSour Control
Con : [1 mark]
It is used
u connect to collections of object from the application.
to conn
Vi

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 : [½ mark]
It is used to connect to XML.

6) ObjectDataSource Control : [½ mark]


It is used to bind data from Generic object to data controls.

18
Prelim Paper Solution

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 flicker-
free pages we just rap the control around the content that we wantt to
update and add the script manager to the page.
Properties
i) Children’s Triggers : This property determine e whether
ther controls

r
located within update panel will cause refresh of the update
pdate panel.

ka
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
an 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
termine whether the control
c is
i always refreshed
(set to always)) or underss certain conditi
condition (Trig
(Triggers).
al
B) ScriptManager
nager Control
ntrol [1 mark]
ScriptManager
Manager acts as a bridge between
betwe client page and server. It
makes
es source that
hat the require ASP.NET AJAX files are included and
required ASP
AJAX
JAX support is added. It must be included on every page where we
wish to add AJAX functionality.
fun
dy

<asp : UpdatePanel
UpdatePanel ID =”UpdatePanel”
I =”U
“server”>
runat = ““se
UpdatePanel>
</asp : UpdatePane
ScriptManager ID = “ScriptManager1”
<asp : ScriptMan
Scr
runat = “server”>
ru
Vi

</asp : ScriptManager>
</a Scr

C) UpdateProgress
UpdatePr Control [1 mark]
Even though there was visual problem in postback but it has one
advantage
adv that user can see something is happening however with update
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.

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

r
Q.6(b) Explain LINQ operators. [5]

ka
(A) Operators in LINQ are as follows

Type Operators
Aggregation Average
Count
an Max
MIN
SUM
Conversion Cast
To Array
rray
Too Dictionary
To Sequence
equence
al
Element Element
men At
first
last
ast
Equality Equal
Equals
Generation
ration
n Range
dy

Group
roup Group By
Joining Join
J
Ordering Order B By Ascending Order By Descending.
Portioning Skip
Tak
Ta
Vi

Quantifying All
Any
Restriction
Restri Where
Selection Select
Set
Set ConCat
Distinct
InterSect
Union

20
Prelim Paper Solution

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

r
like animation and makes it easy to use AJAX in over er application.
ation.

ka
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 e template
plate contains script folder
scripts folde
with necessary JQuery files.
anx 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 n to keep the thing simple and
a revrevisable.
x JQuery simplifies the he process
rocess of html DOM
f traversal of h DO tree.
x It has following features
eatures :
i) Supports thehe event
ent
ii) Supportt AJAX
al
iii) Better
er effects
ects and animations [2 mark]
iv) DOM
OM element
ent selection fun
function
v) Support for CSS
vi) DOM traversal and modification
an modificat
dy

Q.6(d)
d) Explain any
a five methods of o J
Jquery. [5]
(A)) JQUERY EFFECT METHOD [Any Ten Five Mark]
x These methods improves look and feel of website, at client side.
method impro
x These are easy
e to use and are
animate( ) : It performs the specified animation for the element.
1) ani
Vi

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

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

r
element.

ka
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, e, but each working with
w different
diffe
anparameters. [2 mark]
Example: [3mark]
class abc
{
public void Disp(int
nt a)
sp(int
{
Console.WriteLine(a);
e.WriteLine(a);
}
al
public
lic void Disp(int a, int b)
{
Console.WriteLine("{0}{1}",
Console.WriteLin
Console.WriteLine("{0}{1} a,b);
}
}
dy

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

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

22
Prelim Paper Solution

x Assemblies are designed to simplify application deployment and to solve


versioning problems that can occur with component-based applications.

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

r
be run simultaneously (called side-by-side execution).
).
x simplify uninstalling and replicating applications.

ka
Q.7(c) What are the uses of AutoPostBack and runat at properties? [5]
(A) x The AutoPostBack property is used to set or returnturn 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,
an 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
xample sets the AutoPo
AutoPostBack p property to "True" for a
al
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)
dy

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
Vi

<<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>

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]

r
Page
<% @Page.EnableViewState=”false”/>

ka
Control
<asp : TextBox id=”Name” runat=”server” EnableViewState=”false”/>
eViewState=”false”/>
ewState=”false”/>
For Application [[3
3 mark
mark]
< Page enableViewState = “false” /?

anFor Machine
<Page enableViewState=”false” enableViewStateMac=”false”
ableViewStateMac=”false”
ateMac=”false” />

Q.7(e) Explain the term authentication


catio with
cation ASP.NET security.
th respect to AS [5]
(A) The Term authentication n with
ith re
respect ASP.NET security
pect to ASP.NE secu [2mark]
 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
al
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:
dy

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
Vi

every
ry rrequest. Form-based authentication presents the user with an HTML-
based 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

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( )
{

r
} );

ka
Example : [2mark]
[2 mark]
mar
<html>
<head runat=”server”>
<script type=’text/JavaScript” src=”jquery.js”>
uery.js”>
”>
an $(document).ready(function()
{
$(“button”).click (function()
unction()
n()
{
$( “table”).hide();
table”).hide();
e”).hide();
});
});
</script>
al
</head>
<body runat=”server”>
at=”server”>
r”>
<table
e border=1>
border
<tr> <td> 1</td 2</td> <td> 3</td> <td> 4</td>
1</td> <td> 2</td
dy

</tr>
</t
</table>
<input type=”button” value=”Hide”/>
value=”
</body>
</html>
tml>
Vi

‰‰‰‰‰‰

25

Potrebbero piacerti anche