t.y. b.sc. (it) : sem. v asp.net with c# - vidyalankarvidyalankar.org/upload/asp_soln.pdf · t.y....

25
1 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] Q.1(a) Write a program to find reverse of number. [5] (A) Program using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace palindrome { class program { static void Main (String args [ ]) { int n, r, d = 0, n1; Console.WriteLine("Enter the no :"); n = Convert.ToInt32(Console.ReadLine( )); n = n1; while (n1 ! = 0) { r = n1%10; d = d * 10 + r; n1 = n1/10; } Console.WriteLine("Reverse of "+ n + "is" + d ); if (d = = n) Console.WriteLine (n + "is palindrome"); else Console.WriteLine(n + is not palindrome); } } } [1 mark] [3 mark] [1 mark] Vidyalankar [10 [10 [5] [5 args [ ]) [ ]) n1; 1; riteLine("Enter the no :"); "Enter the no :"); vert.ToInt32(Console.ReadLine( )) oInt32(Console.ReadL 1; while (n1 ! = 0) n1 ! = 0 { r = n1%10; r = n1%10 d = d * 10 + r; d = d * 10 + n1 = n1/10; n1 = n1/10; } Console.WriteL Console.WriteL if (d = = n) if (d Console.W else Co } } }

Upload: vokhue

Post on 03-Apr-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

1

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]Q.1(a) Write a program to find reverse of number. [5](A) Program

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace palindrome { class program { static void Main (String args [ ]) { int n, r, d = 0, n1; Console.WriteLine("Enter the no :"); n = Convert.ToInt32(Console.ReadLine( )); n = n1; while (n1 ! = 0) { r = n1%10; d = d * 10 + r; n1 = n1/10; } Console.WriteLine("Reverse of "+ n + "is" + d ); if (d = = n) Console.WriteLine (n + "is palindrome"); else Console.WriteLine(n + is not palindrome); } } }

[1 mark]

[3 mark]

[1 mark]

Vidyala

nkar

[10[10[5][5

args [ ]) [ ])

n1; 1; riteLine("Enter the no :"); "Enter the no :");

vert.ToInt32(Console.ReadLine( ))oInt32(Console.ReadL 1;

while (n1 ! = 0) n1 ! = 0 {

r = n1%10; r = n1%10 d = d * 10 + r; d = d * 10 + n1 = n1/10; n1 = n1/10; } Console.WriteL Console.WriteL if (d = = n) if (d Console.W else Co } } }

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

2

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 mark] (ii) An out parameter must be treated as unassigned value by the function

that uses it. [1 mark] namespace NP1 { class P1 { static void main (string [ ]args) { int a = {11, 12, 13, 14, 15}; int p; // unassigned variable. int max = FindMax (a, out p); Console.WriteLine ("The largest element = " + max + "at position

= " + p); } static int findMax (int [ ]a, out int p) { int m; m = a[0]; p = 0; for(int i = 0; i < a.length; i++) { if(m < a[i]) { m = a[i]; p = i; } } return m; } } }

[2 mark]

[1 marhe function tion

[1 mark] mark

ble. t p);

The largest element = " + max + "atgest element = " + ma

ax (int [ ]a, out int p) nt [ ]a, out int p

a[0]; p = 0;

for(int i = 0; i < a.length; i++) i = 0; i < a.length {

if(m < a[i]) if(m < a[i] { m = a[i]; m = a[i]; p = i; p = i; } } } } return } } } }

ka[2 mark][2 mark]

Prelim Paper Solution

3

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 however in Java / C++. The runtime problem causes abnormal termination of program however in java/C#. There is a mechanism to take corrective action. In case of exception. Exception handing is implemented using following keywords. i) try It contains code that needs to be monitored for occurrence of

exception. It exception is generated in try block there is chance of it being

handled. When exception is generated outside the try block, it cannot be handled and causes abnormal program termination. [1 mark]

ii) catch block It contains exception handling code. [1 mark] iii) throw It is used to manually throw an exception normally used for throwing

user-defined exception. [1 mark] iv) finally It contains code that must be executed whether exception is generated

or not or generated exception is handled or not it is executed before method returns to its caller. [1 mark]

Q.1(d) Explain CLR. [5](A) CLR (COMMON LANGUAGE RUNTIME) [2 mark]

CLR is one of the most essential components of .net framework. CLR is the environment where all programs using .net technologies over

executed. CLR allows the execution of code across different platform by

transmiting code into IL (Intermediate Language). IL is converted into machine language during execution by JIT compiler

(Just-In-Time). During JIT compilation the code is also check for type safety.

Vidyala

nkar

however in r in

rogram however in m however in

on. In case of exception. on. In case of exceptionng keywords. keywords.

be monitored for occurrence onitored for occur

try block there is chance of ck there is cha generated ated outside the try block, ioutside the try

mal program termination. ogram termination.

ption handling co handling code. de.

sed to manually throw an ex manually throw an cept-defined exception. xception.

) finally ly It contains code that must b contains code that mor not or generated excer not or generated exmethod returns to its cethod returns to its c

Q.1(d) Explain CLR.1(d) Explain CL(A) CLR (COMMON L CLR (COM

CLR is one o CLR is t

execu CL

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

4

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 Specification (CLS).

The CLS enables an object or application to interact with the bjects or application of other language.

The classes that follows the rules specified by CLS are termed as CLS compliant classes.

One of the specification defined in CLS is Common Typed System (CTS). CTS provides a type system that is common across all languages. CTS defines rules that ensure that the data object written in various

languages are able to interact with each other. During execution CLR performs following steps :

(a) Loading assemblies & identifies name spaces [1 mark] assemblies are loaded into memory after loading assemblies the

CLR will identifies namespace for the code in assemblies. namespaces are collections of classes (similar package in java)

namespaces are used to organised the classes in hierarchy. The namespaces have public access & this can not be change. (b) JIT Compilation (Just-in-time) [1 mark] Before execution the IL is converted into machine language using

JIT complier. The IL code is examined for following points : The memory location that code needs to access are available. methods are called only through properly define types IL has been correctly generated. (c) Garbage Collection [1 mark] The garbage collection process begins after the JIT compilation. It manages the allocation & de-allocation of memory for an

application. When you create an object the CLR allocates memory for the

object from managed heap.

Vidyala

nkarangua

the bjects or ects o

are termed as CLS ermed as CLS

mon Typed System (CTS). ped System (CTS). across all languages. cross all languages.

data object written in various object written in vah other. r.

owing steps : teps : fies name spaces me spaces [1

d into memory after loading assem memory after loadin namespace for the code in assembpace for the code

e collections of classes (similar p collections of classes (s are used to organised the classes used to organised the c

spaces have public acceve public access & this css &

mpilation (Just-in-time) n (Just-in-time) re execution the IL is converteecution the IL is c

JIT complier. mpliThe IL code is examined for follThe IL code is examined f The memory location that The memory l methods are called onl methods are ca IL has been correctL has been cor

(c) Garbage Collectio(c) Garbage C The garbag The It man

appli W

Prelim Paper Solution

5

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 g) Page_PreRender h) SaveViewsState i) Page_Render j) Page_Unload

Page_Init [1 mark] It contains initialization code for example the server controls are initialized to their default values.

LoadViewState [1 mark] It restores the pages view state information from its last saved state.

Load Post Back Data [1 mark] It populates the server control in your web with the posted data.

PageLoad [1 mark] It restores the control the values of the web page i.e. the data will be binded to the data controls.

Page-PreRender [1 mark] It is called prior to the rendering of page event here we can add code to make changes in the rendered output.

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

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

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

Q.2(b) Explain CSS & its types. [5](A) CSS offers with set of options to change every aspects of web sites. [½ mark]

CSS is understood by all the browsers and so it is used for visual presentation of web pages.

Vidyala

nkar

BackEvent ewsState ate

e_Unload

[1 mark] [1 mare server controls are initialized ver controls are initial

[1 mformation from its last saved statn from its last s

trol intro your web with the posted d our web with the p

ntrol the values of he values o the web pag the w

a controls. rols.

nder d prior to the the rendering of page evndering o

es in the rendered output. s in the rendered output.

ave View State w State It is responsible for saving view responsible for saving

PageRender PageRender It render the content ofIt render the conto the rendered outpu the rendere

Page Unload Page UnloaIt is the last eIt has been rhas discardin

) Ex

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

6

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 style >It cannot be nemed Example [1½ mark] <html> <body> <hl style = “background color:block; fontstyle: Italic>Hello</h1> </body> <html> Embedded CSS [1½ mark] Here the style rule for the element or the clam all id us specified in the head element of the page. Style rule specified will be applied to every html elements on the page. Example: <html> <head> <style type = “text/CSS”> hl { background_color:green; Font face: Arial } </style> </head> </html> External CSS: Here external stylesheet CSS rule is created and only contains style rules. The style rules are applied on every apperance of the elements wherever oppear on the web page. [1½ mark] To link external CSS page on the web page <html> <head> <such fref= “stylesheet.CSS” vel = “Stylesheet” type “text/CSS”/> </head> </html>

Vidyala

nkar

ly style

[1½ mark][1½ mark]

element or t or the clam all id us spethe clam all

be applied to pplied to every html elements every html el

= “text/CSS”> /CSS”>

ground_color:green; ground_color:greeont face: Arial face: Arial

</style> le> </head> </head> </html> </html> External CSS: Here ternal CSS: contains style rulescontains stThe style rules Thoppear on theoppTo link extTo <html> <hea

Prelim Paper Solution

7

Q.2(c) Explain (i) JIT Compilation (ii) Garbage collection [5](A) (i) JIT Compilation: [2½ mark]

JIT complier convert IL to native machine code. It only converts that part of code needed at that instant of time

hence the name Just in Time. Due to JIT complication we can say C# is two time complied

language.

(ii) Garbage collection: [2½ mark] It is a mechanism where memory alloted to object forwhich no

reference exist is regained automatically. It is routine that runs periodically when the system is free or when

an allocation does not have sufficient memory. Q.2(d) Explain delegate with example. [5](A) DELEGATE [3 mark]

class program { delegate int MyDelegate (int x, int y); // delegate static int add (intx, int y) { return (x + y); } static int mul(int x, int y) { return (x * y); } static void main (string [ ] args) { MyDelegate md; // Reference of delegate md = new MyDelegate (add); // function name variable. int P = md(10, 20); // function call Console.WriteLine ("Sum" + P); MyDeletage md1; md1 = new MyDelegate (mul); P = md1(20, 40); Console.WriteLine ("multiplication " + p); } }

Vidyala

nkar

e complied lied

[2½ mark][2½ mark] o object forwhich no t forwhich no

n the system is free or when the system is free or wh memory. ry.

[3

egate (int x, int y); // delegateegate (int x, int y); // dtx, int y) nt y)

(x + y); );

c int mul(int x, int y) mul(int x, int y)

return (x * y); return (x * y } }

static void main (string [ ] static void main (st { { MyDelegate md; MyDelegate md; md = new MyD md = n int P = md( int P Console MyD m

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

8

Note : [2 mark] Delegate is a type that enables you to store references to the function. Delegates are much like function but with no function body. It is declared using delegate keyword. The delegate declaration specifies the return type and parameter list. After defining a delegate you can define a variable of delegate type &

can initialize the variable as reference to function. We can call the function using delegate variable by passing arguments to it.

Q.3 Attempt the following (any TWO) [10]Q.3(a) Explain RadioButton and CheckBox control. [5](A) RadioButton [½ mark]

The RadioButton control is used to display a radio button. Radiobuttons are used to Select single option from multiple options.

Property Description

AutoPostBack A Boolean value that specifies whether the form should be posted immediately after the Checked property has changed or not. Default is false

Checked A Boolean value that specifies whether the radio button is checked or not.

Id A unique id for the control GroupName The name of the group to which this radio

button belongs. [2 mark]

OnCheckedChanged The name of the function to be executed when the Checked property has changed.

Runat Specifies that the control is a server control. Must be set to “server”

Text The text next to the radio button TextAlign On which side of the radio button the text

should appear (rightor left)

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

AutoPostBack 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

Vidyala

nkarr list.

ate type & pe &

arguments to it. ents to it.

[10][10][5][5]

[½[½ mark]mary a radio button. io button.

option from multiple options. n from multiple optio

Descriptioniption nkkkue that specifies whether the pecifies whetheuld be posted immediately aftere posted immed

hecked property has changed or hecked property has changault is false t is false

nA Boolean value that specifies whn value that specradio button is checked or not. o button is checked olaaA unique id for the control unique id for the calaa The name of the group tThe name of thebutton belongs. button belongalyaeckedChanged The name of the eckedChanged The name owhen the CheckwheyayaRunat Specifies thSpeccontrol. MntrodyidyText Text The tee teidyVidyTextAlign On TextAlign

VidyVidVidyCheckbox controCheckbox The Check

Check b

AutoVV

Prelim Paper Solution

9

control is clicked Checked Specifies whether the check box is checked or

not

InputAttributes Attribute names and values used for the Input element for the CheckBox control

[2 mark]

LabelAttributes Attribute names and values used for the Label 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]

The web.config file is an XML based file configuration that contains application wide settings. It is present in applications root directory. We can have more than web.config file for the application but we can have only machine.config file. General form < Configuration > < System.web > < !_Specify compilation, CustomError_Authentication, Authorization . /> < /System .web > < appsettings > < !_Specify file path, connection string, Servername, CustomSettings /> </ appsettings > < /Configuration > We can use web .configuration for following : i) Uses < pages > section to specify whether session or view state is

enabled or disabled. [1 mark]

Example < Configuration > < System .web > < pages enableSessionState = “true”/ > </System.web > </Configuration > ii) We can use < Custom Errors > to specify Application wide Error

information. [1 mark] < Custom Errors mode = “On” >

Vidyala

nkar

el

a control. .

akakaka[5][5]

[2 mark][2 male configuration that contains iguration that co

applications root directory. We caations root directory the application but we can have lication but we c

ilation, CustomError_AuthenticattomError_Autheb >

gs > cify file path, connection e path, connection string, Sst

psettings > /Configuration > Configuration >

We can use web .configuan use web .configuration forati) Uses < pages > section ti) Uses < pages > sectio

enabled or disabled. nabled or disabled.

Example Example < Configurat < Co

< System < S < page </S

ii)

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

10

< 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](A) Global.asax [1 mark]

It is an optional file use to handle application and session level events. The Global.ascx contains code to handle application events that gets triggered during start or end of application. These codes cannot reside in ASP.NET page or web services as it itself are not loaded initially. The Global.ascx is use to declare data that is available across different application request and different browser session. There are two types of Global.ascx file in application domain : i) Event which gets called for every request. ii) Event which gets invoke under certain condition.

For first type of event which occurs in every request are executed in following model : [2 mark] a) Application_ Begin Request ( ) b) Application_AuthenticateRequest ( ) c) Application_AuthorizeRequest ( ) d) Application_ResolveRequestCache ( ) e) ApplicationAcquire_RequestState ( ) f) Application_PreRequestHandlerExecute ( ) g) Application_PostRequestHanlderExecute ( ) h) Application_ReleaseRequestState ( ) i) Application_UpdateRequestCache ( ) j) Application_EndRequest ( )

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

Vidyala

nkar[5]5]

[1 mark] [1 mark] session level events. The n level events. The

events that gets triggered events that gets trigger

T page or web services as it itself or web services a is use to declare data that is a to declare data th

est and different browser sessionerent browser

bal.ascbal.a x file in application domain file in application dled for every request. for every request.

invoke under certain condition. der certain condi

of event which occursent which occurs in every el :

ation_ Begin Request ( ) egin Request ( ) plication_AuthenticateRequest ( ) plication_AuthenticateRequ

Application_AuthorizeRequest ( ) plication_Authoriz) Application_ResolveRequestCaclication_ResolveRe

e) ApplicationAcquipplicationAc re_Request_Reqf) Application_PreRequestHf) Application_PreRequestg) Application_PostRequg) Application_PostRequh) Application_Rele Application_ asei) Application_Updpplicaj) Application_Ej) Applic

For second tFor a) Appli) b) Sec)

Prelim Paper Solution

11

Q.3(d) Explain the text box web server control. List and explain any fourtext box attributes.

[5]

(A) The TextBox control is used to create a text box where the user can input text. [1 mark] Textbox attributes (properties) [4 mark] Properties Description TextMode The type of text box. SingleLine creates a standard text box,

MultiLine creates a textbox that accepts more than one line of text and Password causes the charaacters that are entered to be masked. The default is SingleLine.

Text The text content of the text box. MaxLength The maximum number of characters that can be entered into

the text box. Wrap Determines whether or not text wraps automatically when it

reaches the end of a multiline text box. The default is true. ReadOnly Determines whether the user can change the text in the

textbox. The default is False which means text can be changed.

Columns The width of the text box in characters. The actual width is determined based on the font that’s used for the text entry.

Rows The height of a multi-line text box in lines. The default value is 0 which sets the height to a single line.

Q.4 Attempt the following (any TWO) [10]Q.4(a) Explain MasterPage and steps to create MasterPage. [5](A) Master Page [2 mark]

The master page serves as a template for the other content pages on the site.

The master page has some code-behind methods, and it could auto-generate the page titles for the pages and the other tags which are mentioned in it for each content page.

Master page stores global page elements that occur on every content page.

Extension: ".Master" Content page Stores page-specific elements that are put into the

master. Extension: ".aspx"

Master page code behind can change master page after it acquires content. Extension: ".aspx.cs"

Vidyala

nkar4 mar

rard text box, box, e than one line of one line of

that are entered to re entered rrkaers that can be entered into s that can be entered ikat text wraps automatically when wraps automatically

tiline text box. The default is truxt box. The defaunk the user can change the texter can change fault is False which means te s False which menkf the text box in the text box in characters. Th charac

ed based on the font thed on the font that’s used fat’saneight of a multi-line text f a multi-line text box in lin bo hich sets the height to a single lin ets the height to alaalhe following (any wing (any TWOTW ))

MasterPage and steps to createe and steps to

dyar Page

The master page serves as a t master page servthe site. e site. The master page has sohe master page has generate the page titgenerate the page titmentioned in it for ementioned in Master page stoMastepage. e Extension: Content mastEx

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

12

Creating Master Pages [1 mark] Open the application and add new Item and select “Master Page”. Write any code between the <form>tag of the master page. 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.master.cs"Inherits="MasterPage"%> <html> <head runat="server"> <title></title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <formid="form1"runat="server"> <div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </form> </body> </html>

Any element added to the master page outside the contentplaceholder will appear on every content page that uses the master page.

Q.4(b) What is State management? Explain session in ASP.NET? [5](A) State management [2 mark]

ASP.NET is based on stateless http protocol so every request from client browsed to web server is an independent request is understood as.

State management it a technique used to maintain the state information for asp.net pages cross multiple requests.

Asp.Net comes with built in support for state management both at client side and serves side.

Session state It is duration of communication between client and browses. Session into is

stored per use per session. Session into can be saved in session object at server side. To specify whether or not to use cookie to stare session info In web.config [1 mark] <sessionstate cookieless = “true/false”/>

[2 mark]

Vidyala

nkar

MasterPage.mase.mas

ver"> er">

ntentPlaceHolder1" runat="serveHolder1" runat=

added to the master page to the master page outsid every content page ntent page that uses the at use

t is State management? Explain is State management? tate management management

ASP.NET is based on stateless NET is based on statebrowsed to web server is an ibrowsed to web server is an

State management it a tec State management it a tecasp.net pages cross mulp.net pages cro

Asp.Net comes withAsp.Net cside and serves sside and se

Session staSesIt is durstoreSe

ar

Prelim Paper Solution

13

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 <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 provides following three navigations control. i) Treeview ii) Menu iii) SiteMapPath

i) Treeview [2½ marks] It arranges the pages in hierarchical mannew. The pages are organized

to form a tree structure.

Steps to use treeview control Since tree view control cannot fetch information directly from sitemap

file hence it needs SiteMapDataSource. Drag and drop SiteMapDataSource from tool box Data. It automatically fetches information from SiteMap

file.

Drag and drop treeview from toolbox navigation In treeviewtask In choose datasource select SiteMapData Source Save it Run it.

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

Step to use Menu Control Since menu view control cannot fetch information directly from sitemap

file hence it needs SiteMapDataSource. Drag and drop SiteMapDataSource form toolbox Data. It

automatically fetches information from SiteMap file.

Drag and drop Menu from tool-box navigation

In Menu task In choose datasource Select SiteMapDataSource Save it Run it.

Vidyala

nkar[5]

ASP.Net provides following threNet provides followin

iii) SiteMapPath iii) SiteMapP [

hierarchical mannew. The pages chical mannew. The. e.

iew control ontrol control cannot fetch information cannot fetch infor

needs SiteMapDataSource. SiteMapDataSour rop SiteMapDataSource from MapDataSource fr

x Data. It automatically fetcata. It automatical

rag and drop treeview from ag and drop treeview fromtoolbox box navigation navigation

In treeviewtask treeviewt In choose In c Save it Run it. Save it Run it.

ii) Menu ii) Menu It arranges the pagIt arranges

Step to use Me Step tSince menu file hence

Drag aut

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

14

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 iv) Regular Expression Validator v) Required field validator vi) Validation summary i) Compare validation [1 mark] General form < asp : Compare Validator ID = “CompareValidator1” runnat = “Server” ErrorMessage = “CompareValidator”> < / asp : CompareValidator >

It validates the content of a control by comparing us value with preexisting value or value of other control.

ii) Custom Validator [1 mark] General form < asp : CustomValidator ID = “CustomValidator 1” runnat = “Server” ErrorMessage = “CustomValidator”> </asp : CustomValidator >

It validates the content of the control using Logic specified by the user or customised logic

iii) Range Validator [1 mark] General form < asp : RangeValidator ID = “RangeValidator 1” runnat = “Server” ErrorMessage = “Rang Validator”> </asp : RangeValidator

> It validate the content of the control by ensuring that the value falls within the specified range.

iv) RegularExpressionValidator [1 mark] General form

Vidyala

nkar

[1 mark[

CompareValidator1” eValidator1” age = “CompareValidator”> CompareValidator”>

>

ontent of a control by comparnt of a control by or value of other control. f other control.

idator form

: CustomValidator ID = “CustomVaValidator ID = “Cnnat = “Server” ErrorMessage = “Cnnat = “Server” ErrorMessa

It validates the content of tt validates the contenor customised logic r customised lo

iii) Range Validator ) Range ValidaGeneral form Genera

< asp : RangeV < asp : runnat = “S

> It vaw

Prelim Paper Solution

15

< asp : RegularExpressionValidator ID = “RegularExpressionValidator” runnat = “Server” ErrorMessage = “RegularExpressionValidator”>

</asp : RegularExpressionValidator >

It validates the content of the control by ensuring that the expression mathches the pre-specified pattern.

v) RequriedFieldValidator [1 mark] General form < asp : RequiredFieldValidator ID = “RequiredFieldValidator” runnat = “Server” ErrorMessage = “RequiredFieldValidator”>

</asp : RequiredFieldValidator >

It validates the content of the control by ensuring that the control should not be empty.

Q.5 Attempt the following (any TWO) [10]Q.5(a) Explain ADO.NET architecture. [5](A) ADO.NET ARCHITECTURES [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]

Vidyala

nkarress

[1 mark] mark

idator” alidator”>

by ensuring that the control nsuring that the con

1) DataSet 1) mode.It

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

16

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 use

Oracle, SQL server, OLEDB as data proviers. [2 mark] The DataProvider classes includes : (a) Connection (b) Command (c) Data reader (d) Data Adapter

(a) Connection Object : It is use to establish connection to the db we can use OleDB connection, odbc connection, OracleConnection, SQLConnection.

(b) Command Object : It is use to send SQL Query to the db. we can

use OracleCommand, SqlCommand, etc. The CommandObject makes use of : 1) ExecuteScalar : Returns a single value from query. 2) ExecuteReader : Returns collection of rows & columns as

resultSet. 3) ExecuteNonQuery : Rerform insert, delete, update and returns

integer representing number of rows affected by operation. 4) Execute XMLReader : Returns xmlReader Obj as result of query. (c) DataReader : It is connected, forward, read-only, stream of Data i.e.

use to read sequential collection of record from db. It is faster than DataSet but requires open connection. The

DataReader we can use are : OracleDataReader, SqlDataReader, etc. (d) DataAdapter : It is use in disconnected mode of DataAccess. It acts as

a bridge between Db & DataSet & it populates the data with the data from db.

The DataAdapter provides 2 methods : (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.

Vidyala

nkar

. We can use an us [2 mark] ark]

Adapter dapte

establish connection to the db wsh connection to th odbc connection, OracleConnecconnection, Orac

is use to send SQL Query to the to send SQL Qd, SqlCommand, etc. , SqlCommand, etc.

ject makes use of : makes use of calar : Returns a single value fromurns a single val

eReader : Returns collection er : Returns colleet.

ExecuteNonQuery : Rerform ineNonQuery : Rerfo seinteger representing number of representing nu

4) Execute XMLReader : Return4) Execute XMLReader :

(c) DataReader : It is connect DataReader : It is use to read sequential cuse to read sequent

It is faster than It is faster than DataReader we caDataReade

(d) DataAdapte) Data bridge from

Th

Prelim Paper Solution

17

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; Class Program { PSVM(String[ ] args) { SqlConnection con = new SqlConnection(); SqlCommand cmd = new SqlCommand(); con.ConnectionString = “DataSource = (local)”; InitialCatalog : Student; UserID = sa;

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

try { con.open(); cmd.CommandText = “insert into student (name, number of KT)

values (‘ABC’, 5)”; cmd.Connection = Con; cmd.ExecuteNonQuery(); } catch(Exception e) { } finally {con.Close ( ); }

} }

Q.5(c) Explain security concepts in ASP.NET. [5](A) ASP.NET SECURITY

(a) Authentication (b) Authorization. (c) Impersonation.

(a) Authentication [2 mark] (i) Window mode : (Default) done by IIS. (ii) Form mode : The data is obtained using HTML form & the

Authentication rule is specified by user itself. (iii) Passport Mode : Microsoft provides passport based authentication

when user sign up for the passport then the authentication it is 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.

[2 Mark]

[2 Mark]

[1 Mark]

Vidyala

nkar)”;

stem.Data.SqlClient”; SqlClient”;

t = “insert into student (name, numert into student (nC’, 5)”; ’, 5)”

tion = Con; Con; cuteNonQuery(); nQuery();

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

Explain security concepts in ASP.n security concepts inASP.NET SECURITY NET SECURI(a) Authentication (a) Authentication (a) Authentication a) Authenticatio

(i) Window modei) W (ii) Form mod (ii) For

Authen (iii) Pass

w

(b)

ka[2 Mark][2 Mark]

Ma

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

18

(ii) URL Based : Here the authorization specification is done in web.config file.

<authorization> <[allow/deny] user role> </authorization> (c) Impersonation [1 mark] Here the process identifies itself as a legitimate user and the access

the Resource. specified in <identify> section of web.config file <configuration>

<configuration> <identity impersonate = false> </configuration>

Here impersonate = false means impersonation is not supported.

Q.5(d) Explain the various Data Source controls in ASP.NET. [5](A) DATA SOURCE CONTROLS IN ASP.NET

DataSource provide efficient, flexible & extensible storage for data in ASP.Net

The various DataSourceControls are : 1) Access DataSource Control : [1 mark] It is used to connect to Access DB created using MS-office. Syntax : <asp : Access DataSecure id = “AccessDataSource1” runat =

“server”> </asp>

2) SQLDataSource control : [1 mark] It is used to connect to sql db supported by ADO.Net. Syntax : <asp:SqlDataSource id = “SqlDataSource1” runat = “server”> </asp>

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

4) EntityDataSource contend : [1 mark] It is used to connect to dataSource in EntityDataModel supported by

.Net framework.

5) 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.

Vidyala

nkar

[1 mark]rk]nd the access acces

web.config file onfig file

nation is not supported. not supported.

ntrols in ASP.NET. in ASP.NET. ASP.NET

flexible & extensibble & extensible storage

Controls are : rols are : ce Control : :

onnect to A to Access DB created usinccess DB creatsp : Access DataSecure id = “Acceess DataSecure id

</asp> sp>

SQLDataSource control : QLDataSource cont It is used to connect to sql db s s used to connect t Syntax : <asp:SqlDataSouyntax : <asp:SqlData </asp> </asp

3) LinqDataSource Con) LinqDataSour It is used to connIt is u

4) EntityDataS4) It is use

.Net f

5) X

Prelim Paper Solution

19

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

free pages we just rap the control around the content that we want to update and add the script manager to the page.

Properties i) Children’s Triggers : This property determine whether controls

located within update panel will cause refresh of the update panel. ii) Triggers : The trigger collection contains PostBack Triggers and

AsyncPostBack Trigger. PostBack Trigger is used when we want to force complete page

refresh. AsyncPostBack Trigger is used when you want to update on update

panel. iii) Render Mode : The properly can be set to Inline or Block indicate

whether this update panel renders itself as <div> element or span element.

iv) Update Mode : It determine whether the control is always refreshed (set to always) or unders certain condition (Triggers).

B) ScriptManager Control [1 mark] ScriptManager acts as a bridge between client page and server. It

makes source that the required ASP.NET AJAX files are included and AJAX support is added. It must be included on every page where we wish to add AJAX functionality.

<asp : UpdatePanel ID =”UpdatePanel” runat = “server”> </asp : UpdatePanel> <asp : ScriptManager ID = “ScriptManager1” runat = “server”> </asp : ScriptManager>

C) UpdateProgress 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 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.

Vidyala

nkar flicke

we want to t to

e whether controls ther controls of the update panel. pdate panel.

s PostBack Triggers and Back Triggers and

want to force complete page to force complete

when you want to update on up you want to upda

erly can be set to Inline or Bloc set to Inline panel renders itself as < renders itself as div> elem

t determine whether the control itermine whether the c) or unders s certain condition (Trigcertain conditi

nager Control ntrol Manager acts as a bridge betw acts as a bridge e

es source that the required ASP hat the requireJAX support is added. It must JAX support is added. It

wish to add AJAX functionality. to add AJAX fun <asp : UpdatePane <asp : UpdatePanel ID =”Ul I runat = “se runat = “ </asp : UpdatePane </asp : UpdatePane <asp : ScriptMan <asp : Scr ru </asp : Scr </a

C) UpdatePrC) Even

adv

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

20

Properties i) DisplayAfter : It determines the time in milliseconds that the

control has to wait before it displays its content.

D) TimerControl [1 mark] The timercontrol is use for executing server side code on repetitive

basis. e.g. we can use it to update the content of update panel after every 5 seconds

Q.6(b) Explain LINQ operators. [5](A) Operators in LINQ are as follows

Type Operators Aggregation Average

Count Max MIN SUM

Conversion Cast To Array To Dictionary To Sequence

Element Element At first last

Equality Equals Generation Range Group Group By Joining Join Ordering Order By Ascending Order By Descending. Portioning Skip

Tak Quantifying All

Any Restriction Where Selection Select Set ConCat

Distinct InterSect Union

Vidyala

nkar ma

repetitivetive

el after every 5 very 5

[5][5]

kakakakk rray

o Dictionary To Sequence equence anElement men At At first first last ast aly Equals Equalyady

ration Range n Range

dya

dyroup Group Group By BydydyJoining Join Joining JdydyOrdering Ordering Order BOrder BidyVdyPortioning Skip Portioning

Ta

VidVd

Quantifying Quantifying ViVRestriction RestriVVSelection VVSet VV

Prelim Paper Solution

21

Q.6(c) Explain Jquery and advantages. [5](A) JQUERY [3 mark]

To overcome the disadvantage of JavaScript we use JQuery. Initially developed by John Resign in 2006. It became very popular

clientside framework and Microsoft has started shipping the Microsoft product with JQuery.

The main focus of JQuery Library is to simplify the way we access the element in our webpage.

It provide helps in working with clientside events, enable visual effects like animation and makes it easy to use AJAX in over application.

We can download the latest version of JQuery from site http://jquery.com

Beside down loading the library from jquery website, any new website that is created using ASP.NET website template contains scripts folder with necessary JQuery files.

JQuery increases the size of your webpage and hence it is a deliberate choice to include it on your page or not.

JQuery helps the program to keep the code simple and conside. JQuery library is design to keep the thing simple and revisable. JQuery simplifies the process of traversal of html DOM tree. It has following features :

i) Supports the event ii) Support AJAX iii) Better effects and animations iv) DOM element selection function v) Support for CSS vi) DOM traversal and modification

Q.6(d) Explain any five methods of Jquery. [5](A) JQUERY EFFECT METHOD [Any Ten Five Mark]

These methods improves look and feel of website, at client side. These are easy to use and are

1) animate( ) : It performs the specified animation for the element. 2) ClearQueue( ) : To remove all queued function for the element. 3) delay( ) : To set delay for all queued function for the element. 4) fade In( ) : It changes the opacity of the element from hidden to

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.

[2 mark]

Vidyala

nkaricroso

we access the ss th

nable visual effects visual effects er application. ation.

of JQuery from site Query from site

uery website, any new website website, any new wee template contains scripts foldeplate contains script

our webpage and hence it is a delpage and hence it iage or not.

to keepep the code simple and cons the code simplen to keep the thing simple and revn to keep the thing simple a

he process rocess of traversal of html DOf traversal of h eatures :

he event ent t AJAX

er effects and animations ects and animations OM element selection function ent selection fun

Support for CSS Support for CSSvi) DOM traversal and modificat DOM traversal an

d) Explain anyd) Explain a five methods of Jfive methods o)) JQUERY EFFECT METHODJQUERY EFFECT METHOD

These methods impro These method These are easy to These are e

1) animate( ) : ani2) ClearQu3) delay4) fad

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

22

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

of the element. 12) stop( ) : Stop the animation of selected element. 13) Toggle : This method toggles between hide and show method for the

element.

Q.7 Attempt the following (any THREE) [10]Q.7(a) What is method overloading? Explain with example. [5](A) Method overloading provides the programmer with the capability to create

multiple methods with the same name, but each working with different parameters. [2 mark]

Example: [3 mark] class abc

{ public void Disp(int a)

{ Console.WriteLine(a);

} public void Disp(int a, int b)

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

} }

class Program {

staticvoid Main(string[] args) {

abc a1 = newabc(); a1.Disp (10);

a1.Disp (10,20); }

} Q.7(b) Purpose of assembly in .Net Framework. [5](A) The purpose of assembly in .Net Framework: [2 mark] Assemblies 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

Vidyala

nkar

SlideDown own

how method for the ethod for the

[10][ example.e [5]

mmer with the capability to creat with the capability toe, but each working with diffe each working w

[2

sp(int a) nt a)

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

lic void Disp(int a, int b) Disp(int a, int

Console.WriteLine("{0}{1}Console.WriteLin} }

ss Program ogram {

staticvoid Main(stringtaticvoid Main(s { {

abc a1 = neabc a1 = ne a1.Disp ( a1

a1.Dis } }

}}

Q.7(b) Purpose ofb) PurA) The pur

A

Prelim Paper Solution

23

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

Enable developers to specify version rules between different software components.

Provide the infrastructure to enforce versioning rules. Provide the infrastructure to allow multiple versions of a component to

be run simultaneously (called side-by-side execution). simplify uninstalling and replicating applications. Q.7(c) What are the uses of AutoPostBack and runat properties? [5](A) The AutoPostBack property is used to set or return whether or not an

automatic post back occurs when the user selects an item in a list control.

If this property is set to TRUE the automatic post back is enabled, otherwise FALSE. Default is FALSE.

Syntax <asp:SomeListControl AutoPostBack="TRUE|FALSE" runat="server"/>

[2 mark] Example: [3 mark] The following example sets the AutoPostBack property to "True" for a RadioButtonList control: <script runat="server"> Sub Change(obj As Object, e As EventArgs) Response.Write("You selected " & rb1.SelectedItem.Text) End Sub </script>

<form runat=server> <asp:RadioButtonList id="rb1" AutoPostBack="True" runat="server" OnSelectedIndexChanged="Change"> <asp:ListItem Text="Item 1" /> <asp:ListItem Text="Item 2" /> </asp:RadioButtonList> </form>

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

Vidyala

nkar ma

softwarar

of a component to omponent to ).

at properties? [5] properties? set or return whether or not an turn whether or

the user selects an item in a lser selects an

an automatic post

anE.

lan AutoPostBack="TRUE|FALSE" run utoPostBack="TRUE|FA

xample sets the AutoPo sets the AutoPostBack p

st control: ol:

yarver">

ya Object, e As E

dyaonse.Write("You selected

dydypt>

idyVidyform runat=server>

Vidy<asp:RadioButtonL

Vidat="server"

Vid <asp:ListIVi <V</asV</f

RunatRu

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

24

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

field can be disabled? [5]

(A) Viewstate can be disabled at the following places in the web application. 1. Page 2. Control 3. Application 4. Machine [2 mark]

Page <% @Page.EnableViewState=”false”/> Control <asp : TextBox id=”Name” runat=”server” EnableViewState=”false”/> For Application < Page enableViewState = “false” /?

For Machine <Page enableViewState=”false” enableViewStateMac=”false” />

Q.7(e) Explain the term authentication with respect to ASP.NET security. [5](A) The Term authentication with respect to ASP.NET security [2 mark]

Authentication is the process of obtaining identification credentials such as name and password from a user and validating those credentials against some authority.

If the credentials are valid, the entity that submitted the credentials is considered an authenticated identity.

There are three ways of doing authentication and authorization in ASP.NET: Windows authentication [1 mark]

In this methodology ASP.NET web pages will use local windows users and groups to authenticate and authorize resources.

Forms Authentication [1 mark] This is a cookie based authentication where username and password are

stored on client machines as cookie files or they are sent through URL for every request. Form-based authentication presents the user with an HTML-based Web page that prompts the user for credentials.

Passport authentication [1 mark] 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.

[3 mark]

Vidyala

nkarate

plication. n. ne [2 mark] ark]

eViewState=”false”/> ewState=”false”/>

ableViewStateMac=”false” /> ateMac=”false”

cation catio with respect to ASP.NET th respect to ASn with reith respect to ASP.NET secupect to ASP.NE

alass of obtaining id

alaord from a user an

arity

yaials are valid, the e

ya authenticated id

dya are three ways of doing a

dydows authenticati

dyn this methodology AS

idyroups to authenticate a

Vidyorms Authentication

VidThis is a coo

Vidstored

Viry rVVVV

ka[3 mark

Prelim Paper Solution

25

Q.7(f) What is the use of Document Ready Event and explain with example.

[5]

(A) Document.Ready(): [3 mark] It is used to prevent any JQuery code from running before the

document is finished loading because there are few functions which can fail if they run before the document is loaded.

General form- $(document).ready(function( )

{ } ); Example : [2 mark] <html> <head runat=”server”> <script type=’text/JavaScript” src=”jquery.js”> $(document).ready(function() { $(“button”).click (function() {

$( “table”).hide(); }); }); </script> </head> <body runat=”server”> <table border=1>

<tr> <td> 1</td> <td> 2</td> <td> 3</td> <td> 4</td> </tr>

</table> <input type=”button” value=”Hide”/> </body> </html>

Vidyala

nkarhich c

[2[2 mark]mar

uery.js”> ”>

unction() n()

table”).hide(); e”).hide();

at=”server”> r”> e border=1> e border

<tr> <td> 1</td> <td> 2</td <tr> <td> 1</td </tr> </t

</table> </table> <input type=”button” value=”<input type=”button” value=”</body> </body> </html> tml>