Você está na página 1de 8

Model Answer

TY B.Sc (IT), Semester V, Second Half 2013


Subject : ASP.NET with C#

Marks : 60

Note : The solution set is prepared with great efforts. Kindly go through it and
assess papers.
I.

Answer any two of the following:

10

a. What is .NET Framework? What is in the .NET Framework?


.NET Framework is a platform created by Microsoft for developing Windows
applications, web applications and web services. .NET Framework runs on Windows
OS. .NET Framework has been designed such that it can be used from any language.
This includes C#, C++, Visual Basic, Jscript and COBOL. These languages can
communicate with each other that is it is possible for C# developers to make use of code
written by Visual Basic.NET programmers, and vice versa.
.NET Framework consists of a large library of code that we use in our client languages
such as C# using Object Oriented Programming Techniques. This library is categorised
into different modules one module contains the building blocks for Windows
applications, another for network programming, and another for web development. Part
of the library defines some basic types data types, example 32 bit signed integer. A
type is a representation of data and specifying some of the most fundamental of these
facilitates interoperability between languages using the .NET Framework. This is called
the Common Type System (CTS). The framework also includes the .NET Common
Language Runtime (CLR), which is responsible for maintaining the execution of all
applications developed using .NET library.
If students have stressed on CLR only, marks can be allotted as per the examiners
choice.
b. What is Method Overloading? What are the steps involved for the selection of a method
in Method Overloading?
C# allows us to create more than one method with the same name, but with the different
parameter lists and different definitions. This is called method overloading. Overloaded
methods must differ in number of parameters, type of parameters and order of
parameters. Methods return type does not play any role in the overload resolution.
An example program should be given here...............
The method selection involves the following steps:
1) The complier tries to find exact match in which the types of actual parameters
are the same and uses that method.
2) If exact match is not found then the compiler tries to use the implicit conversions
to actual arguments and then uses the method whose match is unique. If the
conversion creates multiple matches then the compiler will generate an error
message.

c. What is the difference between overriding methods and hiding methods?


Overriding methods :
In method overriding we can override a method in base class by creating similar method
in derived class this can be achieved by using inheritance principle and using virtual &
override keywords. If we want to override base class method then we need to declare
base class method with virtual keyword and the method which we created in derived
class to override base class need to declare with override keyword like as shown below
using System;
namespace ConsoleApplication3
{
class SampleA
{
public virtual void Show()
{
Console.WriteLine("Sample A Test Method");
}
}
class SampleB:SampleA
{
public override void Show()
{
Console.WriteLine("Sample B Test Method");
}
}
class Program
{
static void Main(string[] args)
{
SampleA a=new SampleA();
SampleB b=new SampleB();
a.Show();
b.Show();
a = new SampleB();
a.Show();
Console.ReadLine();
}
}
}
Output
Sample A Test Method
Sample B Test Method
Sample B Test Method
Hiding methods:
To hide base class methods in derived classes we can declare derived class methods with
new keyword. To use new keyword we need to write the code like as shown below
2

using System;
namespace ConsoleApplication3
{
class SampleA
{
public void Show()
{
Console.WriteLine("Sample A Test Method");
}
}
class SampleB:SampleA
{
public new void Show()
{
Console.WriteLine("Sample B Test Method");
}
}
class Program
{
static void Main(string[] args)
{
SampleA a=new SampleA();
SampleB b=new SampleB();
a.Show();
b.Show();
a = new SampleB();
a.Show();
Console.ReadLine();
}
}
}
Output
Sample A Test Method
Sample B Test Method
Sample A Test Method
d. Write a C# program to do the following: Initialise an array A with 10 elements. Initialize
an array B with 7 elements. Divide each element of array A with each element of array
B that is a[0] / b[0], a[1] / b[1] etc. Implement the same to handle Divide by zero error
and Index out of bound error.
using System;
class testexcep
{
public static void Main()
{
int[] a = {4,6,8,10,12,14,16,18,20,22};
int[] b = {2,0,4,0,6,0,8};
for(int i = 0; i < a.Length; i++)
{
try
3

{ Console.WriteLine({0} / {1} is {2}, a[i], b [i], a[i] / b[i]); }


catch(DivideByZeroException)
{ Console.WriteLine(Divide By Zero Error); }
catch(IndexOutOfRangeException)
{ Console.WriteLine( Index Out of Bound Error); }
}
}
}
II.

Answer any two of the following:

10

a. Delegates in C# are used for Event Handling. Justify this statement with a relevant
example program.
Delegates are useful for two main reasons:
First, delegates support events. Second, delegates give your program a way to execute
methods at runtime without having to know precisely what those methods are at compile
time.
Events :
An important C# feature is built upon the foundation of delegates: the event. An event
is, essentially, an automatic notification that some action has occurred. Events work like
this: An object that has an interest in an event registers an event handler for that event.
When the event occurs, all registered handlers are called. Event handlers are represented
by delegates. Events are members of a class and are declared using the event keyword.
Its most commonly used form is shown here:
event event-delegate event-name;
Here, event-delegate is the name of the delegate used to support the event, and eventname is the name of the specific event object being declared.
A simple example:
using System;
// Declare a delegate type for an event.
delegate void MyEventHandler();
// Declare a class that contains an event.
class MyEvent {
public event MyEventHandler SomeEvent;
// This is called to raise the event.
public void OnSomeEvent() {
if(SomeEvent != null)
SomeEvent();
}
}
class EventDemo {
// An event handler.
static void Handler() {
Console.WriteLine("Event occurred");
}
static void Main() {
MyEvent evt = new MyEvent();
// Add Handler() to the event list.
evt.SomeEvent += Handler;
// Raise the event.
evt.OnSomeEvent();
}
}
Output :
Event occurred
The students can write any example and should explain the same if comment lines
are not written along with the program as shown above.

b. What is the significance of Assemblies in .NET?


When we compile an application the MSIL code created is stored in an assembly.
Assemblies include both executable application files that we can run directly from
Windows without the need for any other programs (these have a .exe file extension), and
libraries for use by other applications (which have .dll extension).
Assemblies also contain metadata (information about information contained in the
assembly) and optional resources(additional data used by the MSIL, such as sound files
and pictures).
This means that deploying applications is as simple as copying the files into a directory
on a remote computer and running the executable file from this directory (assuming the
.NET CLR is installed).
There are two types of assemblies:
1) Private assembly -- This is normally used by a single application, and is stored in the
applications directory, or sub-directory beneath.
2) Shared assembly -- This is used by multiple applications, and is normally stored in the
global assembly cache(GAC), which is a central repository for assemblies. The main
reason for deploying assemblies to the GAC is that the GAC can support multiple
versions of the same assembly side-by-side.
The students can write any relevant general explanation.

c. List and explain the use of any five namespaces in c#.


1) The System namespace contains fundamental classes and base classes that define
commonly-used value and reference data types, events and event handlers,
interfaces, attributes, and processing exceptions.
2) The System.Collections namespace contains interfaces and classes that define
various collections of objects, such as lists, queues, bit arrays, hash tables and
dictionaries.
3) The System.Text.RegularExpressions namespace contains classes like Regex,
Match and MatchCollection Class that provide access to the .NET Framework
regular expression engine.
4) The System.Data namespace provides access to classes that represent the
ADO.NET architecture. ADO.NET lets you build components that efficiently
manage data from multiple data sources.
5) The System.Drawing parent namespace contains types that support basic GDI+
graphics functionality.
The students can write any five namespaces......

d. What is the need of CSS in ASP.NET? Explain the different types of CSS in ASP.NET.
Need for CSS:
The purpose of CSS is to separate the style information / presentation / design elements
from the content / structural logic of a document. CSS is concerned with how a document
should appear onscreen, when the viewer is using a graphical web browser and to achieve
this CSS uses style sheet rules which control different properties such as color, font,
border, back ground, margins, alignment, etc.
Different types of CSS:
1) Inline style sheet : In this style specification are placed right within the html elements.
Example:
<h1 style = color:white; font-family:arial; font-size:14pt> Example of Inline CSS
</h1>
2) Embedded or Internal style sheet : In this style specifications are placed within the
head section of the web page and they affect all corresponding tags on the web page.
Example:
<head>
<title> Embedded CSS </title>
<style type=text/CSS>
body { background:black}
h1 { color:white; font-family:arial; font-size:14pt; text-align:center; }
</style>
</head>

3) External style sheet : In this CSS is placed in a separate file and so it is much easier
to reuse the CSS code, that is instead of typing the same CSS code on every web page,
simply refer them to a single CSS file with the link tag.
Example:
<head>
<link rel = stylesheet type = text/css href = stylesheet.css>
</head>

III.

Answer any two of the following:


a. Explain the text box web server control. List and explain any four text box attributes.

10

Text box server control is used to type single line of text or multiple line of text.
Attributes:
TextMode, Text, MaxLength, Columns, Rows, Wrap, ReadOnly (with explanation)
b. What is the difference between check box and radio button control? What are the
common attributes associated with these controls?
Difference between check box and radio button controls is that radio buttons in groups
are mutually exclusive and check boxes operate independently. In other words if the user
selects one radio button in a group, all of the other radio buttons in the same group are
automatically turned off. In contrast, when a user selects a check box, it has no effect on
other check boxes.
Common attributes:
Text, Checked, GroupName (with explanation)
c. Explain any five properties of List box and Drop-down list controls.
Properties:
Items, Rows, SelectedItem, SeelctedIndex, SelctedValue, SelectionMode(with
explanation)
d. What is the difference between .aspx file and .cs file?Explain with an example for each.
Any relevant explanation and code snippet written with respect to the practical
knowledge is appreciated.
IV. Answer any two of the following:
a. In a web form the details of an employee is filled in after he/she is employed in the
company. In the design there is a text box to fill the first name, a text box to fill the last
name, a text box to fill the surname, a text box to enter email address, a text box to enter
the email address again to confirm the same, a text box to fill the age. What are the
validation controls that have to be added for each field in the form?

10

All possible validation controls for the respective controls should be added.
b. Explain the role of view state and session state in ASP.NET.
View state:
1. View state of a web form is available only within that web form.
2. View state is stored on the page in a hidden field called _ViewState. Because of this the
View state will be lost, if you navigate away from the page, or if the browser is closed.
3. View state is used by all asp.net controls to retain their state across postback.
Session state:
1. Session state variables are available across all pages, but only for a given single session.
Session variables are like single-user global data.
2. Session state variables are stored on the web server.
3. Session state variables are cleared, when the user session times out. The default is 20
minutes. This is configurable in web.config.
These are the general points. Students can write points pertaining to these points and can
give example code snippets too.

c. What is the significance of Master pages in ASP.NET? What is the name given to pages
other than master pages? Explain in detail.
With most web sites, only a part of the page changes, when you go from one page to the
another. To create web pages with a consistent layout you need to define these relatively
static regions in a single page that is master page which enables you to define the look
and feel of all the pages in your site in a single location. A master page is not true ASPX
page and cannot be requested in the browser directly, it only serves as the template that
real pages called content pages are based on.
A master page has a code behind file identified by its CodeFile and Inherits attributes:
%@Master Language =C# AutoEventWireup=true CodeFile=Frontend.master.cs
Inherits = MasterPages_Frontend %
To create regions that content pages can fill in, you need to define ContenPlaceHolder
controls in your page like this:
<asp:ContenPlaceHolder
ID=
ContenPlaceHolder1
runat
=server>
</asp: ContenPlaceHolder>
%@Page Titile= Language =C# MasterPageFile = Frontend.master..............
The page specific content is then put inside a Content control that points to the relevant
ContenPlaceHolder
<asp:Content ID=Content1 ContenPlaceHolderID = ContenPlaceHolder1
runat =server </asp:Control>
d. Explain Menu and Treeview site navigation controls.
TreeView Control:
--Home
Home
--Reviews
By Genre
All Reviews
--Gig Pics
Gig Pics
New Album
--About
Contact Us
About Us
My Profile
Login
This can display the structure of your site and enables you to expand and collapse the
different nodes. In the above figure the entire tree is expanded.
To create a tree view you have to add one Tree View control to your page and hook it up
to a SiteMapDataSource control and you are done. A Web.sitemap file has to be created
first to do the same. The data used by treeview control is not limited to the Web.sitemap
file however. You can also bind it to regular XML files and even create a treeview or its
items called nodes programmatically.
Menu Control:
Home Home
Reviews By Genre
Gig Pics All Reviews
About
Login
The menu control initially only displays the home menu item. However as soon as you
move the mouse over the menu item Reviews a submenu appears.
To create a basic menu you have to add one menu control to your page and hook it up to
a SiteMapDataSource control and you are done. A Web.sitemap file has to be created
first to do the same.
7

This is just a guide to the answer. Students have to write the steps to use both the
controls.
V.
a.
b.
c.
d.

Answer any two of the following:


What is the use of GridView control in ASP.NET?
Explain FormView control.
Explain the term authentication with respect to ASP.NET security.
What is the difference between authorisation and impersonation in terms of security in
ASP.NET?

10

Question No. V Any relevant answers written with respect to the practical session
done should also be considered, as theory is of less importance with respect to these
topics.
VI. Answer any two of the following:
a. Explain the LINQ query syntax with an example query.

10

Example query:
var myquery =
from myc in objcountries
where myc.country == India
select myc.countrycode;
foreach(string strname in myquery)
{ Console.WriteLine(strname) }
Here objcountries can be any datasource like SQL Server, XML documents, ORACLE
etc. Data necessary is in myquery.
Students should explain every line mentioned above in detail.
b. Explain the terms Take, Skip, TakeWhile, SkipWhile, First, FirstOrDefault, Last,
LastOrDefault with respect to LINQ.
Take gets the requested number of elements from the result set and them ignores the
rest, whereas skip ignores the requested number of elements and then returns the rest.
TakeWhile and SkipWhile query operators work in a similar way but enable you to take
or skip records while a specific condition is true. First, FirstOrDefault, Last,
LastOrDefault returns the first and last element in a specific sequence of objects. First
and Last throw an error when the collection is empty, whereas the other two operators
return the default value for the relevant data types.
c. Explain the use of UpdateProgress Control and Timer Control in AJAX.
Any relevant example design and code written and explained to show the use of
UpdateProgress Control and Timer Control can be appreciated.
d. What are the different types of selectors present in JQuery? Explain.
Different types of Selectors:
1) The Universal selector:
$(*).css(font-family,Arial);
2) The ID selector:
$(#Button1).addClass(NewClassName);
3) The Element selector:
$(h2).css(color,blue);
4) The Class selector:
<h1 class = highlight> Heading 1 </h1>

<h2> Heading 2 </h2>


<p class = highlight> First Paragraph</p>
<p> Second Paragraph </p>
$(.highlight).css(background-color,red);
5) Grouped and Combined Selectors:
$(h1, h2).css(color, orange);
$(#Maincontent p).css(border, 1px solid red);

Você também pode gostar