ASP.NET with C#
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]
ka
Vi
dy
al
an
ka
r
[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
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
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.
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
x
x
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
Vi
dy
al
an
ka
r
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]
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
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"
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
[1 mark]
Vi
dy
al
an
ka
r
[2 mark]
10
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
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>
[1 mark]
[1 mark]
Vi
dy
al
an
ka
r
Treeview
[2
[
marks]
It arranges the pages in hierarchical
chical mannew. The
Th pages are organized
to form a tree structure.
e.
ii) Menu
[2 marks]
pages in menoform or it creates menu of pages.
It arranges the pag
Vi
dy
al
an
ka
r
Compare validation
General form
< asp : Compare Validator ID = CompareValidator1
CompareValidator1
eValidator1
runnat = Server ErrorMessage
age = CompareValidator>
CompareValidator>
< / asp : CompareValidator >
[ mark
[1
mark]
[1 mark]
14
Vi
dy
al
an
ka
r
v) RequriedFieldValidator
General form
< asp : RequiredFieldValidator ID = RequiredFieldValidator
idator
runnat = Server ErrorMessage = RequiredFieldValidator>
alidator>
</asp : RequiredFieldValidator >
Q.5
Attempt the following (any TWO)
Q.5(a) Explain ADO.NET architecture.
(A)
ADO.NET ARCHITECTURES
[10]
[5]
[2 mark]
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
16
Vi
dy
al
an
ka
r
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
Vi
dy
al
an
ka
r
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
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
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
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
Vi
dy
al
an
ka
r
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
Vi
dy
al
an
ka
r
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
{
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
Vi
dy
al
an
ka
r
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
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 />
24
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