0% found this document useful (0 votes)
185 views27 pages

AWP ATKT Solution Set April 2019 Ketaki Ghawali

The document is a university paper solution providing answers to questions about .NET Framework architecture, array memory representation, properties and methods of the Math class, type conversion, value and reference types, static members, and partial classes. It includes diagrams and code examples to explain each topic in detail across multiple pages.

Uploaded by

harshit sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views27 pages

AWP ATKT Solution Set April 2019 Ketaki Ghawali

The document is a university paper solution providing answers to questions about .NET Framework architecture, array memory representation, properties and methods of the Math class, type conversion, value and reference types, static members, and partial classes. It includes diagrams and code examples to explain each topic in detail across multiple pages.

Uploaded by

harshit sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

BSc.

(Information Technology)
(Semester V)
2018-19

Advanced Web
Programming
(USIT 503 Core)
University Paper Solution

By
Ms. Ketaki Ghawali

Ms. Ketaki Ghawali Page 1


Question 1

Q1a. Draw and explain .NET Framework architecture.

Ans:

- The .NET Framework is an integral Windows component that supports building and running
the next generation of applications and XML Web services.
- Windows Forms application do not access the operating System or computer
hardware directly.
- Instead they use services of the .NET Framework, which in turn access the operating
system.
- The .NET Framework has two main components: the Common Language Runtime
and the .NET Framework Class Library.
- .NET Framework Class Library
- Consists of segments of pre-written code called classes that provide many of the
functions that required for developing .NET applications.
- Eg. The Windows Forms classes are used for developing Windows Forms
applications.
- And related Classes are organized into groups called namespaces.
- Eg. System.Windows.Forms namespace contains the classes you use to create forms.
- Common Language Runtime(CLR)
- Provides the services that are needed for executing any application that’s developed
with one of .NET languages.
- This is possible because all of the .NET languages compile to a common intermediate
language .
- CLR also provides the Common Type System(CTS) that defines the data types that
are used by all .NET languages.
- Because all of .NET applications are managed by the CLR they are sometimes referred
to as Managed applications.

Ms. Ketaki Ghawali Page 2


Q1b. Elaborate Array memory representation with example.

Ans: Below is the diagrammatic representation of an array in memory:

- Arrays allow you to store a series of values that have the same data type.
- Each individual value in the array is accessed by using one or more index numbers.
- Typically, arrays are laid out contiguously in memory.
- All arrays start at a fixed lower bound of 0.
- When you create an array in C#, you specify the number of elements.
- Because counting starts at 0, the highest index is actually one less than the number of
elements.
string[] stringArray = new string[4];
// Create a 2x4 grid array (with a total of eight integers).
- int[,] intArray = new int[2, 4];
- By default, if the array includes simple data types, they are all initialized to default
values (0 or false), depending on whether you are using some type of number or a
Boolean variable.
- But if the array consists of strings or another object type, it’s initialized with null
references.
- You can also fill an array with data at the same time that you create it.
- string[] stringArray = {"1", "2", "3", "4"};
- The same technique works for multidimensional arrays, except that two sets of curly
braces are required:
// Create a 4x2 array (a grid with four rows and two columns).
int[,] intArray = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};

Q 1c. Explain any 5 properties/methods of Math class.


Ans.
- Abs()
- This method returns the absolute value of a specified number.
- myValue = Math.Abs(-10); // myValue = 10.0

- Pi()
- This method returns the pi value 3.14.
- myValue = Math.PI;

Ms. Ketaki Ghawali Page 3


- Round()
- This method rounds a value to the nearest integer or to the specified number of
fractional digits.
- myValue = Math.Round(42.889, 2); // myValue = 42.89

- Log()
- This method Returns the logarithm of a specified number.
- myValue = Math.Log(24.212); // myValue = 3.18..

- Sqrt()
- This method returns the square root of a specified number.
- myValue = Math.Sqrt(81); // myValue = 9.0

Q1d. Give details about Type Conversion.

Ans:
- Conversions are of two types: widening and narrowing.
- Widening conversions always succeed.
- For example, you can always convert a 32-bit integer into a 64-bit integer.
int mySmallValue;
long myLargeValue;
mySmallValue = Int32.MaxValue;
myLargeValue = mySmallValue;
- On the other hand, narrowing conversions may or may not succeed, depending on
the data.
- If you’re converting a 32-bit integer to a 16-bit integer, you could encounter an error
if the 32-bit number is larger than the maximum value that can be stored in the 16-
bit data type.
- All narrowing conversions must be performed explicitly.
- C# uses a method for explicit type conversion.
- To convert a variable, you simply need to specify the type in parentheses before the
expression you’re converting.
- The following code shows how to change a 32-bit integer to a 16-bit integer:
int count32 = 1000;
short count16;
count16 = (short)count32;
- This process is called casting.

Q1e. Write short note on value and reference types.

Ans:

- Value Type
- Value type variables can be assigned a value directly.
- They are derived from the class System.ValueType.
- The value types directly contain data.
- When you declare an int type, the system allocates memory to store the value.
- Value Type variables are stored in the stack.

Ms. Ketaki Ghawali Page 4


- Examples are int, char, and float, which stores numbers, alphabets, and floating point
numbers, respectively.
- Example:

static void ChangeValue(int x)


{
x = 200;

Console.WriteLine(x);
}

static void Main(string[] args)


{
int i = 100;

Console.WriteLine(i);

ChangeValue(i);

Console.WriteLine(i);
}

- Reference Type
- It refers to a memory location. Using multiple variables, the reference types can refer to a
memory location.
- If the data in the memory location is changed by one of the variables, the other variable
automatically reflects this change in value.
- Reference Type variables are stored in the heap.
- Example of built-in reference types are −
- object

- dynamic

- string

- Example:
static void ChangeReferenceType(Student std2)
{
std2.StudentName = "Steve";
}

static void Main(string[] args)


{
Student std1 = new Student();
std1.StudentName = "Bill";

ChangeReferenceType(std1);

Console.WriteLine(std1.StudentName);
}

Ms. Ketaki Ghawali Page 5


Q1f. Explain static members and partial class.

Ans:
- Static members
- The usual way to communicate with a class is to create a new instance of the class
and then work on the resulting object.
- In most cases, classes are the ability to instantiate multiple copies of the same class
and then use them differently in some way.
- However, in some cases, you might like to have a class which you may use without
instantiating it, or at least a class where you can use members of it without creating
an object for it.
- For instance, you may have a class with a variable that always remains the same no
matter where and how it's used. This is called a static member, because it remains the
same.
- A class can be static, and it can have static members, both functions and fields.
- A static class can't be instantiated, so in other words, it will work more as a grouping
of related members than an actual class.
- public static class Rectangle
- {
- public static int CalculateArea(int width, int height)
- {
- return width * height;
- }
- }
- Partial Class
- When you define your class with the partial keyword, you or someone else is allowed
to extend the functionality of your class with another class, which also needs to be
declared as partial.
- This is useful in the following situations:
- When you have a very large class - you can then keep it in multiple files, to make it
easier to work with various parts of the classes. For instance, you could have all the
properties in one file and all the methods in another file, while still just having one
class.
- When you work with a designer, like the one in Visual Studio - for instance with
WinForms, where all the automatically generated designer code can be kept in
one file, while your code is kept in another file.

- PartialClass1.cs

using System;

namespace PartialClasses
{
public partial class PartialClass
{
public void HelloWorld()
{
Console.WriteLine("Hello, world!");
}
}
}

- PartialClass2.cs

Ms. Ketaki Ghawali Page 6


using System;

namespace PartialClasses
{
public partial class PartialClass
{
public void HelloUniverse()
{
Console.WriteLine("Hello, universe!");
}
}
}
- Program.cs
using System;

namespace PartialClasses
{
class Program
{
static void Main(string[] args)
{
PartialClass pc = new PartialClass();
pc.HelloWorld();
pc.HelloUniverse();
}
}
}

Question 2

Q2a. list and explain any five templates to create ASP.NET applications.

Ans:
- The following are the five templates to create ASP.NET applications:
- ASP.NET Web Forms Site
- This creates a full-featured ASP.NET website, with its basic infrastructure already in
place. This website includes a master page that defines the overall layout (with a
header, footer, and menu bar) and two ready-made web pages, named default.aspx
and about.aspx. It also includes an Accounts folder with pages for registration, login,
and password changing.
- ASP.NET Empty Website
- This creates a nearly empty website. It includes a stripped-down web.config
configuration file, and nothing else. It’s easy to fill in the pieces you need as you start
coding.
- ASP.NET Dynamic Entities Website
- This creates an ASP.NET website that uses the ASP.NET Dynamic Data feature. There
are actually two dynamic data templates, which use slightly different approaches to
communicating with your database.
- WCF Service
- This creates a WCF service—a library of server-side methods that remote clients (for
example, Windows applications) can call.
- ASP.NET Reports Website
- This creates an ASP.NET website that uses the ReportView control and SQL Server
Reporting Services (a tool for generating database reports that can be viewed and
managed over the Web). The ASP.NET Crystal Reports Web Site template provides a
similar service, but it uses the competing Crystal Reports software.

Ms. Ketaki Ghawali Page 7


Q2b. Explain Anatomy of a Webform.

Ans:

- ASP.NET applications are generally divided into multiple Web pages. Every Web page
in an ASP.NET application shares a common set of resources and configuration
settings.
- Each ASP.NET application is executed inside a separate application domain. These
application domains ensure that even if a Web application causes a fatal error, it does
not affect other applications that are currently running on the same computer.
- Each Web application is a separate entity that has its own set of data. It can be
described as a combination of files, pages, handlers, modules, and executable code
that can be invoked from a virtual directory on a Web server.
- Directories Used in ASP.NET Web Applications:
- Bin: Stores all the compiled .NET components (DLLs) that an ASP.NET Web
application uses.
- App_Code: Stores source code files that are dynamically compiled to be used in the
Web application.
- App_Browsers: Stores browser definition files.
- App_GlobalResources: Stores global resources that are accessible to every page in
the Web application.
- App_LocalResources: Stores .resx files that are accessible to a specific page only.
- App_WebReferences: Stores references to Web services that are used by the Web
application.
- App_Data: Stores data such as database files and XML files that are used by the
application.
- App_Themes: Stores the themes that are used in the Web application.
- Files used in ASP.NET Web Applications:

Ms. Ketaki Ghawali Page 8


- Ends with .aspx: These are ASP.NET Web pages that contain the user interface and,
optionally, the underlying code.
- Ends with .ascx: These are ASP.NET user controls.
- Ends with .asmx: These are ASP.NET Web Services.
- web.config: This is the XML-based configuration file for ASP.NE applications.
- Global.asax: This is the global application file.
- Ends with .cs: These are code-behind files that contain C# code.
- Ends with .ashx: These are default HTTP handlers for all Web handlers that do not
have a user interface.
- Configuration Files used in ASP.NET Web Applications:
- A configuration file is an XML file that contains configuration settings for an
application and has a .config extension.
- It provides the following benefits:
- Provides control and flexibility over the way you run applications.
- Eliminates the need to recompile the application every time a setting changes.
- Controls access to protected resources and the location of remote applications and
objects by defining configuration settings.
- Server Settings - Machine.config - Present at the root of the configuration
hierarchy.
- Root Web settings - Web.config - Present in the same directory as machine.config.
- Website settings (optional) - Web.config - Present in the root directory of each IIS
website.
- Application root settings (optional) - Web.config - Present in the root directory of
each application.
- Application subfolder (optional) - Web.config - Present in a subfolder of the
application root.

Q2c. Write a short note on Page Class.

Ans:
- Every web page is a custom class that inherits from System.Web.UI.Page.
- By inheriting from this class, your web page class acquires a number of properties
and methods that your code can use.
- These include properties for enabling caching, validation, and tracing.
- The following table shows the various properties of the Page Class:
Property Description
isPostBack This Boolean property indicates whether this is the first time the page is
being run (false) or whether the page is being resubmitted in response
to a control event, typically with stored view state information (true).
EnableViewState When set to false, this overrides the EnableViewState property of the
contained controls, thereby ensuring that no controls will maintain
state information.
Application This collection holds information that’s shared between all users in your
website. For example, you can use the Application collection to count
the number of times a page has been visited.
Session This collection holds information for a single user, so it can be used in
different pages. For example, you can use the Session collection to
store the items in the current user’s shopping basket on an e-
commerce website.
Cache This collection allows you to store objects that are time-consuming to
create so they can be reused in other pages or for other clients. This

Ms. Ketaki Ghawali Page 9


technique, when implemented properly, can improve performance of
your web pages.
Request This refers to an HttpRequest object that contains information about
the current web request. You can use the HttpRequest object to get
information about the user’s browser
Response This refers to an HttpResponse object that represents the response
ASP.NET will send to the user’s browser.
Server This refers to an HttpServerUtility object that allows you to perform a
few miscellaneous tasks. For example, it allows you to encode text so
that it’s safe to place it in a URL or in the HTML markup of your page.
User If the user has been authenticated, this property will be initialized with
user information.

Q2d. Explain any five properties of List box and DropdownList controls.

Ans: Listbox
- Items:
- Items property used to add item into the listbox control. It is indicate
the collection of items in the listbox.
- Text
- Text Property specify the Text display in the listbox.
- Value
- The value property is invisible value, but we can get the value while
programming. Each item has a text and value with in it.
- SelectedValue
- Returns the Value property of the selected item of the listbox.
- SelectedIndex
- Returns the Index of selected item of listbox. (Index always start from
Zero).
Dropdown List
- Count
- Return the total count of items in the dropdownlist.
- Add
- Add the new item in to the dropdownlist control.
- Insert
- Add the new item at specific position in dropdownlist control.
- Remove
- Remove the item from the dropdownlist control.
- Clear
- Clear all the items from dropdownlist control.

Q2e. Write a note on AdRotator control.

Ans:
- The AdRotator control randomly selects banner graphics from a list,
which is specified in an external XML schedule file.
- This external XML schedule file is called the advertisement file.
- The AdRotator control allows you to specify the advertisement file
and the type of window that the link should follow in the
AdvertisementFile and the Target property respectively.
- The basic syntax of adding an AdRotator is as follows:

Ms. Ketaki Ghawali Page 10


<asp:AdRotator runat = "server" AdvertisementFile = "adfile.xml" Target =
"_blank" />

- The advertisement file is an XML file, which contains the information


about the advertisements to be displayed.
- The advertisement file needs to be a structured text file with well-defined
tags delineating the data.
- There are the following standard XML elements that are commonly used
in the advertisement file:

Element Description

Advertisements Encloses the advertisement file.

Ad Delineates separate ad.

ImageUrl The path of image that will be displayed.

NavigateUrl The link that will be followed when the user clicks the ad.

AlternateText The text that will be displayed instead of the picture if it cannot
be displayed.

Keyword Keyword identifying a group of advertisements. This is used for


filtering.

Impressions The number indicating how often an advertisement will appear.

Height Height of the image to be displayed.

Width Width of the image to be displayed.

Q2f. Brief about Graphics class and it’s any 5 methods.

Ans:

- Graphics objects are the heart of GDI+. They are represented by the Graphics class,
which defines methods and properties to draw and fill graphics objects.
- Whenever an application needs to draw or paint something, it has to use the Graphics
object.
- We can divide Graphics class methods into three categories: draw, fill, and
miscellaneous.
- Draw methods are used to draw lines, curves, and outer boundaries of closed curves
and images.

Ms. Ketaki Ghawali Page 11


- Fill methods fill the interior area of graphics objects. There are also a few miscellaneous
methods that fall in neither category-for example, MeasureString and Clear.
- Following are the methods of the graphics class:

DrawArc Draws an arc (a portions of an ellipse specified by a pair of coordinates,


a width, a height, and start and end angles).

DrawCurve Draws a cardinal spline through a specified array of Point structures.

DrawEllipse Draws an ellipse defined by a bounding rectangle specified by a pair of


coordinates, a height, and a width.

DrawLine Draws a line connecting two points specified by coordinate pairs.

DrawRectangle Draws a rectangle specified by a coordinate pair, a width, and a height.

Question 3

Q3a. Explain exception Handling mechanism in C# with its key features.

Ans:
- When an error occurs in your application, the .NET Framework creates an exception
object that represents the problem.
- You can catch this object by using an exception handler.
- If you fail to use an exception handler, your code will be aborted, and the user will see
an error page.
- If you catch the exception, you can notify the user, attempt to resolve the problem, or
simply ignore the issue and allow your web page code to keep running.
- Exception handling provides several key features:
- Exceptions are object-based:
- Each exception provides a significant amount of diagnostic information wrapped into
a neat object, instead of a simple message and error code. These exception objects
also support an InnerException property that allows you to wrap a generic error over
the more specific error that caused it. You can even create and throw your own
exception objects.
- Exceptions are caught based on their type:
- This allows you to streamline error-handling code without needing to sift through
obscure error codes.
- Exception handlers use a modern block structure:
- This makes it easy to activate and deactivate different error handlers for different
sections of code and handle their errors individually.
- Exception handlers are multilayered:
- You can easily layer exception handlers on top of other exception handlers, some of
which may check for only a specialized set of errors. This gives you the flexibility to
handle different types of problems in different parts of your code, thereby keeping
your code clean and organized.

Ms. Ketaki Ghawali Page 12


- Exceptions are a generic part of the .NET Framework:
- This means they’re completely cross-language compatible. Thus, a .NET component
written in C# can throw an exception that you can catch in a web page written in VB.

Q3b. What are state management techniques in ASP.Net?

Ans:

- The state management techniques are as follows:


- View State
- It is used for storing user data in ASP.NET. Sometimes in ASP.NET applications, users
want to maintain or store their data temporarily after a post back. In this case, VIEW
STATE is the most used and preferred way of doing this mechanism.
- This property is enabled by default, but we can make changes according to our
functionality, what we need to do is just change EnableViewState value to
either TRUE for enabling it or FALSE for opposite operation.
- Hidden Field
- Hidden field is used for storing small amount of data on client side. It’s just a
container that contains some objects but their result does not get rendered on our
web browser. It is invisible in the browser.
- It stores one value for the single variable and it is the preferable way when a
variable’s value is hanged frequently but we don’t need to keep track of that every
time in our application or web program.
- Cookies
- Cookie is a small text file that gets stored in users hard drive using client’s browser.
Cookies are just used for the sake of user’s identity matching as it only stores
information such as sessions ids, some frequent navigation or postback request
objects.
- Whenever we get connected to the internet for accessing particular service, that
cookie file gets accessed from our hard drive via our browser for identifying user. The
cookie access depends upon the life cycle of expiration of that particular cookie file.
- Control State
- Control state is based on custom control option. For expected results from CONTROL
STATE, we need to enable the property of view state.
- Query Strings
- Query strings are used for some specific purpose. These in general case are used for
holding some value from a different page and move these values to the different
page. The information stored in it can be easily navigated from one page to another
or to the same page as well.

Q3c. Elaborate cookies with suitable code snippet.

Ans:

- Cookies are small files that are created in the web browser’s memory (if they’re
temporary) or on the client’s hard drive (if they’re permanent).
- One advantage of cookies is that they work transparently, without the user being
aware that information needs to be stored.
- They also can be easily used by any page in your application and even be retained
between visits, which allows for truly long-term storage.

Ms. Ketaki Ghawali Page 13


- They suffer from some of the same drawbacks that affect query strings—namely,
they’re limited to simple string information, and they’re easily accessible and readable
if the user finds and opens the corresponding file.
- Before you can use cookies, you should import the System.Net namespace so you can
easily work with the appropriate types:
- using System.Net;
- To set a cookie, just create a new HttpCookie object.
// Create the cookie object.
HttpCookie cookie = new HttpCookie("Preferences");
// Set a value in it.
cookie["LanguagePref"] = "English";
// Add another value.
cookie["Country"] = "US";
// Add it to the current web response.
Response.Cookies.Add(cookie);

Q3d. What is cross page posting? Explain with an example.

Ans:

- A cross-page postback is a technique that extends the postback mechanismso that


one page can send the user to another page, complete with all the information for
that page.
- The infrastructure that supports cross-page postbacks is a property named
PostBackUrl, which is defined by the IButtonControl interface and turns up in button
controls such as ImageButton, LinkButton, and Button.
- To use cross-posting, you simply set PostBackUrl to the name of another web form.
- When the user clicks the button, the page will be posted to that new URL with the
values from all the input controls on the current page.
- Here’s an example, a page named CrossPage1.aspx that defines a form with two text
boxes and a button.
- When the button is clicked, it posts to a page named CrossPage2.aspx.
CrossPage1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CrossPage1.aspx.cs"
Inherits="CrossPage1" %>
<html ="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>CrossPage1</title>
</head>
<body>
<form id="form1" runat="server" >
<div>
First Name:
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<br />
Last Name:
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<br />
<br />

Ms. Ketaki Ghawali Page 14


<asp:Button runat="server" ID="cmdPost"
PostBackUrl="CrossPage2.aspx" Text="Cross-Page Postback" /><br />
</div>
</form>
</body>
</html>
CrossPage2
public partial class CrossPage2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
lblInfo.Text = "You came from a page titled " +
PreviousPage.Title;
}
}
}
Q3e. Explain Master Page with its uses and working.
Ans:
- Master pages are similar to ordinary ASP.NET pages. Like ordinary pages, master
pages are text files that cancontain HTML, web controls, and code.
- However, master pages have a different file extension .master instead of .aspx, and
they can’t be viewed directly by a browser.
- Instead, master pages must be used by other pages, which are known as content
pages.
- Essentially, the master page defines the page structure and the common ingredients.
- The content pages adopt this structure and just fill it with the appropriate content.
- For example, if a website such as http://www.amazon.com were created using
ASP.NET, a single master page might define the layout for the entire site.
- Every page would use that master page, and as a result, every page would have the
same basic organization and the same title, footer, and so on.
- However, each page would also insert its specific information, such as product
descriptions, book reviews, or search results, into this template.
- The master pages can be used to accomplish the following:
o Creating a set of controls that are common across all the web pages and
attaching them to all the web pages.
o A centralized way to change the above created set of controls which will
effectively change all the web pages.
o Dynamically changing the common UI elements on master page from content
pages based on user preferences.
- To create a master page, we need to:
o Go to "Add New Item".
o Select the MasterPage.
o Let's say our master page is MasterPageOne.Master.
o We will now add a menu bar on this master page on top of the page. This
Menu bar will be common to all the pages (since it is in Masterpage).
o Once we have menubar added, we can have content pages use the master
page.
o Let's add few content pages like default.aspx, about.aspx, Contact.aspx.
o When we add these content pages, we need to remember to select the option
of "Use master Page" and select the master page.

Ms. Ketaki Ghawali Page 15


- Once we have all the master pages and content pages ready, we can test run our
website.

Q3f. What is Theme? Explain Global theme.


Ans:
- A theme decides the look and feel of the website. It is a collection of files that define
the looks of a page.
- It can include skin files, CSS files & images.
- We define themes in a special App_Themes folder.
- Inside this folder is one or more subfolders named Theme1, Theme2 etc. that define
the actual themes.
- The theme property is applied late in the page's life cycle, effectively overriding any
customization you may have for individual controls on your page.
- Global Themes:
- Built-in themes are saved in a special location under the installation path of the .NET
Framework 2.0:
%SystemRoot%\Microsoft.NET\Framework\VX.X.XXXX\ASP.NETClientFiles\Themes\
- The actual name of the subdirectory labeled vX.X.XXXX changes according to the build
of ASP.NET 2.0 that you're considering.
- Themes defined in this path are visible to all applications running on the machine.
- However, ASP.NET 2.0 Beta 2 users will not find this folder in the specified location
because ASP.NET team has dropped the Global Themes support from the beta 2 release
of the product.
- But once they provide pre-defined themes as an add-on, they can be purchased or
downloaded separately and will be installed in the specified folder above.

Question 4

Q4a. Explain the SQL Data Provider Model.

Ans:
- ADO.NET relies on the functionality in a small set of core classes. You can divide these classes
into two groups:
- Those that are used to contain and manage data (such as DataSet, DataTable, DataRow, and
DataRelation) and those that are used to connect to a specific data source (such as Connection,
Command, and DataReader).
- The data container classes are completely generic.
- No matter what data source you use, after you extract the data, it’s stored using the same data
container: the specialized DataSet class. Think of the DataSet as playing the same role as a
collection or an array—it’s a package for data.
- The difference is that the DataSet is customized for relational data, which means it understands
concepts such as rows, columns, and table relationships natively.
- The second group of classes exists in several flavors. Each set of data interaction classes is
called an ADO.NET data provider.
- Data providers are customized so that each one uses the best-performing way of interacting
with its data source. For example, the SQL Server data provider is designed to work with SQL
Server.
- Internally,it uses SQL Server’s tabular data stream (TDS) protocol for communicating, thus
guaranteeing the best possible performance.
- If you’re using Oracle, you can use an Oracle data provider.

Ms. Ketaki Ghawali Page 16


- Each provider designates its own prefix for naming classes. Thus, the SQL Server provider
includes SqlConnection and SqlCommand classes, and the Oracle provider includes
OracleConnection and OracleCommand classes.
- Internally, these classes work quite differently, because they need to connect to different
databases by using different low-level protocols.
- Externally, however, these classes look quite similar and provide an identical set of basic
methods because they implement the same common interfaces.
- This means your application is shielded from the complexity of different standards and can use
the SQL Server provider in the same way the Oracle provider uses it.

Q4b. Give details about DataReader with example.

Ans.

-DataReader provides an easy way for the programmer to read data from a database as
if it were coming from a stream.
- The DataReader is the solution for forward streaming data through ADO.NET.
- A data reader provides read-only, forward-only access to the data in a database.
- DataReader is also called a firehose cursor or forward read-only cursor because it
moves forward through the data.
- The DataReader not only allows us to move forward through each record of database,
but it also enables us to parse the data from each column.
- The DataReader class represents a data reader in ADO.NET.
Example:

This example read all the records from customer table using DataReader class.

string SQL = "SELECT * FROM Customers";

SqlConnection conn = new SqlConnection(ConnectionString);

// create a command object

SqlCommand cmd = new SqlCommand(SQL, conn);

conn.Open();

// Call ExecuteReader to return a DataReader

SqlDataReader reader = cmd.ExecuteReader();

Ms. Ketaki Ghawali Page 17


Console.WriteLine("customer ID, Contact Name, " + "Contact Title, Address ");

Console.WriteLine("=============================");

while (reader.Read())

Console.Write(reader["CustomerID"].ToString() + ", ");

Console.Write(reader["ContactName"].ToString() + ", ");

Console.Write(reader["ContactTitle"].ToString() + ", ");

Console.WriteLine(reader["Address"].ToString() + ", ");

//Release resources

reader.Close();

conn.Close();

Q4c. What is Data Binding? Explain its types.

Ans:
- Data binding in ASP.NET is superficially similar to data binding in the world of desktop
or client/server applications, but in truth, it's fundamentally different. In those environments,
data binding involves creating a direct connection between a data source and a control in an
application window.
- If the user modifies the data in a data-bound control, our program can update the
corresponding record in the database, but nothing happens automatically.
- ASP.NET data binding is much more flexible than old-style data binding. Many of the
most powerful data binding controls, such as the GridView and DetailsView, give us
unprecedented control over the presentation of our data, allowing us to format it, change its
layout, embed it in other ASP.NET controls, and so on.
- Types of ASP.NET Data Binding
- Two types of ASP.NET data binding exist: single-value binding and repeated-value
binding. Single-value data binding is by far the simpler of the two, whereas repeated-value
binding provides the foundation for the most advanced ASP.NET data controls.
- Single-Value, or "Simple," Data Binding
- We can use single-value data binding to add information anywhere on an ASP.NET
page. We can even place information into a control property or as plain text inside an HTML
tag.
- Single-value data binding doesn't necessarily have anything to do with ADO.NET. Instead,
single-value data binding allows us to take a variable, a property, or an expression and
insert it dynamically into a page.
- Repeated-Value, or "List," Binding
- Repeated-value data binding allows us to display an entire table (or just a single field
from a table). Unlike single-value data binding, this type of data binding requires a
special control that supports it.
- Typically, this will be a list control such as CheckBoxList or ListBox, but it can also be a
much more sophisticated control such as the GridView.

Ms. Ketaki Ghawali Page 18


Q4d. Write a short note on Data Source Controls.

Ans:

- The Data source control connects to and retrieves data from a data source and makes
it available for other controls to bind to, without requiring code. ASP.NET allows a
variety of data sources such as a database, an XML file, or a middle-tier business object.
- The common data source controls are:
- AccessDataSource – Enables you to work with a Microsoft Access database.
- XmlDataSource – Enables you to work with an XML file.
- SqlDataSource – Enables you to work with Microsoft SQL Server, OLE DB, ODBC, or
Oracle databases.
- ObjectDataSource – Enables you to work with a business object or other class
- SiteMapDataSource – Used for ASP.NET site navigation.
- EntityDataSource - Enables you to bind to data that is based on the Entity Data Model.
- LinqDataSource – Enables you to use Language-Integrated Query (LINQ) in an
ASP.NET Web page.

Q4e. Explain the ways of formatting the GridView data for display.

Ans:

FORMATTING FIELDS
- Each BoundField column provides a DataFormatString property you can use to
configure the appearance of numbers and dates using a format string.
- Format strings generally consist of a placeholder and a format indicator, which are
wrapped inside curly brackets.
- A typical format string looks something like this: {0:C}
- In this case, the 0 represents the value that will be formatted, and the letter indicates
a predetermined format style. Here, C means currency format, which formats a
number as an amount of money (so 3400.34 becomes $3,400.34, assuming the web
server is set to use U.S. regional settings).
- Here’s a column that uses this format string:
- <asp:BoundField DataField = "UnitPrice" HeaderText = "Price"DataFormatString =
"{0:C}" />

Ms. Ketaki Ghawali Page 19


- if you want to write the BirthDate value in the format month/day/year (as in
12/30/12), you use the following column:
<asp:BoundField DataField = "BirthDate" HeaderText = "Birth Date"
DataFormatString = "{0:MM/dd/yy}" />

USING STYLES
- The GridView exposes a rich formatting model that’s based on styles.

<asp:GridView ID = "GridView1" runat = "server" DataSourceID = "sourceProducts"


AutoGenerateColumns = "False">
<RowStyle BackColor = "#E7E7FF" ForeColor = "#4A3C8C" />
<HeaderStyle BackColor = "#4A3C8C" Font-Bold = "True" ForeColor = "#F7F7F7" />
<Columns>
<asp:BoundField DataField = "ProductID" HeaderText = "ID" />
<asp:BoundField DataField = "ProductName" HeaderText = "Product Name" />
<asp:BoundField DataField = "UnitPrice" HeaderText = "Price" />
</Columns>
</asp:GridView>
- To create a column-specific style, you simply need to rearrange the control tag so
that the formatting tag becomes a nested tag inside the appropriate column tag.
Here’s an example that formats just the ProductName column:
<asp:GridView ID = "GridView2" runat = "server" DataSourceID = "sourceProducts"
AutoGenerateColumns = "False" >
<Columns>
<asp:BoundField DataField = "ProductID" HeaderText = "ID" />
<asp:BoundField DataField = "ProductName" HeaderText = "Product Name">
<ItemStyle BackColor = "#E7E7FF" ForeColor = "#4A3C8C" />
<HeaderStyle BackColor = "#4A3C8C" Font-Bold = "True" ForeColor = "#F7F7F7" />
</asp:BoundField>
<asp:BoundField DataField = "UnitPrice" HeaderText = "Price" />
</Columns>
</asp:GridView>

Ms. Ketaki Ghawali Page 20


Q4f. Write short note on selecting a GridView row.

Ans:
Selecting an item refers to the ability to click a row and have it change color (or become
highlighted) to indicate that the user is currently working with this record.

- At the same time, you might want to display additional information about the record
in another control. With the GridView, selection happens almost automatically once
you set up a few basics.
- Before you can use item selection, you must define a different style for selected items.
- The SelectedRowStyle determines how the selected row or cell will appear. If you don’t
set this style, it will default to the same value as RowStyle, which means the user won’t
be able to tell which row is currently selected.
- Usually, selected rows will have a different BackColor property.
- To find out what item is currently selected (or to change the selection), you can use the
GridView.SelectedIndex property. It will be -1 if no item is currently selected.
- Also, you can react to the SelectedIndexChanged event to handle any additional
related tasks. For example, you might want to update another control with additional
information about the selected record.
ADDING A SELECT BUTTON
- The GridView provides built-in support for selection. You simply need to add a
CommandField column with the ShowSelectButton property set to true.
- ASP.NET can render the CommandField as a hyperlink, a button, or a fixed image.
- You choose the type using the ButtonType property. You can then specify the text
through the SelectText property or specify the link to the image through the
SelectImageUrl property.
- Here’s an example that displays a select button:
<asp:CommandField ShowSelectButton = "True" ButtonType = "Button"
SelectText = "Select" />
- And here’s an example that shows a small clickable icon:
<asp:CommandField ShowSelectButton = "True" ButtonType = "Image"
SelectImageUrl = "select.gif" />

Question 5

Q5a. Write short note on XML TextReader Class.

Ans:
- Reading the XML document in your code is just as easy with the corresponding
XmlTextReader class.
- The XmlTextReader moves through your document from top to bottom, one node at a
time.
- You call the Read() method to move to the next node. This method returns true if there
are more nodes to read or false once it has read the final node.
- The current node is provided through the properties of the XmlTextReader class, such as
NodeType and Name.
- A node is a designation that includes comments, whitespace, opening tags, closing tags,
content, and even the XML declaration at the top of your file.
- To get a quick understanding of nodes, you can use the XmlTextReader to run through
your entire document from start to finish and display every node it encounters.
Example:
String xmlNode="~\XMLFile.xml";

Ms. Ketaki Ghawali Page 21


XmlReader xReader = XmlReader.Create(xmlNode);
while (xReader.Read())
{
switch (xReader.NodeType)
{
case XmlNodeType.Element:
ListBox1.Items.Add("<" + xReader.Name + ">");
break;
case XmlNodeType.Text:
ListBox1.Items.Add(xReader.Value);
break;
case XmlNodeType.EndElement:
ListBox1.Items.Add("</" + xReader.Name + ">");
break;
}
Q5b. Explain the reading process from an XML Document with example.

Ans:

- Reading the XML document in your code is just as easy with the corresponding
XmlTextReader class.

- The XmlTextReader moves through your document from top to bottom, one node at a
time.

- You call the Read() method to move to the next node. This method returns true if there
are more nodes to read or false once it has read the final node.

- The current node is provided through the properties of the XmlTextReader class, such
as NodeType and Name.

- A node is a designation that includes comments, whitespace, opening tags, closing tags,
content, and even the XML declaration at the top of your file.

- To get a quick understanding of nodes, you can use the XmlTextReader to run through
your entire document from start to finish and display every node it encounters.

string file = Path.Combine(Request.PhysicalApplicationPath,

@"App_Data\SuperProProductList.xml");

FileStream fs = new FileStream(file, FileMode.Open);

XmlTextReader r = new XmlTextReader(fs);

// Use a StringWriter to build up a string of HTML that

// describes the information read from the XML document.

StringWriter writer = new StringWriter();

// Parse the file, and read each node.

while (r.Read())

// Skip whitespace.

Ms. Ketaki Ghawali Page 22


if (r.NodeType == XmlNodeType.Whitespace) continue;

writer.Write("<b>Type:</b> ");

writer.Write(r.NodeType.ToString());

writer.Write("<br>");

// The name is available when reading the opening and closing tags

// for an element. It’s not available when reading the inner content.

if (r.Name != "")
{
writer.Write("<b>Name:</b> ");
writer.Write(r.Name);
writer.Write("<br>");
}
// The value is when reading the inner content.
if (r.Value != "")
{
writer.Write("<b>Value:</b> ");
writer.Write(r.Value);
writer.Write("<br>");
}
if (r.AttributeCount > 0)
{
writer.Write("<b>Attributes:</b> ");
for (int i = 0; i < r.AttributeCount; i++)
{
writer.Write(" ");
writer.Write(r.GetAttribute(i));
writer.Write(" ");
}
writer.Write("<br>");
}
writer.Write("<br>");
}
fs.Close();
// Copy the string content into a label to display it.
lblXml.Text = writer.ToString();

Q5c. Define Authentication and Authorization. Give types of Authentication.

Ans:

- Authentication:
- This is the process of determining users identities and forcing those users to prove
they are who they claim to be. Usually, this involves entering credentials (typically a
user name and password) into some sort of login page or window. These credentials
are then authenticated against the Windows user accounts on a computer, a list of
users in a file, or a back-end database.

Ms. Ketaki Ghawali Page 23


- Authorization:
- Once a user is authenticated, authorization is the process of determining whether that
user has sufficient permission to perform a given action (such as viewing a page or
retrieving information from a database). Windows imposes some authorization
checks (for example, when you open a file), but your code will probably want to
impose its own checks (for example, when a user performs a task in your web
application such as submitting an order, assigning a project, or giving a promotion).
- Authentication and authorization are the cornerstones of a secure user-based site. The
Windows operating system provides a good analogy. When you first boot up your
computer, you supply a user ID and password, thereby authenticating yourself to the
system. After that step, every time you interact with a restricted resource (such as a
file, database, registry key, and so on), Windows quietly performs authorization checks
to ensure your user account has the necessary rights.
- You can use two types of authentication to secure an ASP.NET website:
- Forms authentication:
- With forms authentication, ASP.NET is in charge of authenticating users, tracking
them, and authorizing every request. Usually, forms authentication works in
conjunction with a database where you store user information (such as user names
and passwords), but you have complete flexibility. You could even store user
information in a plain text file or write customized login code that calls a remote
service. Forms authentication is the best and most flexible way to run a subscription
site or e-commerce store.
- Windows authentication:
- With Windows authentication, the web server forces every user to log in as a Windows
user. (Depending on the specific configuration you use, this login process may take
place automatically, as it does in the Visual Studio test web server, or it may require
that the user type a name and password into a login dialog box.) This system requires
that all users have Windows user accounts on the server (although users could share
accounts). This scenario is poorly suited for a public web application, but it is often
ideal for an intranet or company-specific site designed to provide resources for a
limited set of users.

Q5d. What is Windows Authentication. Give details.

Ans:

- It causes the browser to display a login dialog box when the user attempts to access
restricted page.
- It is supported by most browsers.
- It is configured through the IIS management console.
- It uses windows user accounts and directory rights to grant access to restricted pages

- Steps to use Windows authentication:


- When we configure our ASP.NET application as windows authentication it will use
local windows user and groups to do authentication and authorization for our
ASP.NET pages.
- In ‘web.config’ file set the authentication mode to ‘Windows’ as shown in the below
code snippets.

Ms. Ketaki Ghawali Page 24


<authentication mode="Windows"/>
- We also need to ensure that all users are denied except authorized users. The below
code snippet inside the authorization tag that all users are denied. ‘?’ indicates any
<authorization>
<deny users="?"/>
</authorization>
- We also need to specify the authorization part. We need to insert the below snippet
in the ‘web.config’ file .stating that only ‘Administrator’ users will have access to
<location path="Admin.aspx">
<system.web>
<authorization>
<allow roles="questpon-srize2\Administrator"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
- The next step is to compile the project and upload the same on an IIS virtual
directory. On the IIS virtual directory we need to ensure to remove anonymous access
and check the integrated windows authentication.
- Now if we run the web application we will be popped with a userid and password box.

Q5e. Explain AJAX with its advantages and disadvantages.

Ans:

- AJAX (Asynchronous JavaScript and XML) is not a single technology, it is a collection


of technologies that, when used together, enable developers to build an RIA.
- These technologies allow a web page to communicate with a web server and update
the page after it’s loaded without having to reload the entire page. This can also reduce
the load on the web server.
- Each time a standard HTTP request and response cycle is performed, the entire page is
returned from the server and the page is loaded into the browser.
- This type of request and response is required the first time a page is requested even if
the page is AJAX-enabled.
- With an AJAX HTTP request and response cycle, the browser can request just the
information it need to update the page.
- Then, the updated information that’s returned from the server can be used to update
the page without having to reload it.
- Advantages:

- The key benefit of Ajax is responsiveness. An Ajax application, when done properly,
provides a better experience for the user.

- Even if the user can’t do anything new (or do anything faster), this improved experience
can make your web application seem more modern and sophisticated.

- Ajax can also provide genuinely new features that aren’t possible in traditional web
pages.

- For example,Ajax pages often use JavaScript code that reacts to client-side events such
as mouse movements and key presses.

- These events occur frequently, so it’s not practical to deal with them by using the
postback model.

Ms. Ketaki Ghawali Page 25


- With the postback approach,you’d need to send the entire page back to the web server,
regenerate it, and refresh it in the browser—by which point the mouse might be
somewhere completely different. This approach is clearly impractical.

- However, an Ajax page can deal with this scenario because it can react immediately,
updating the page if needed or requesting additional information from the web server
in the background. While this request is under way, the user is free to keep working
with the page. In fact, the user won’t even realize that the request is taking place.

- Disadvantages:

- There are two key challenges to using Ajax.

- The first is complexity. Writing the JavaScript code needed to implement an Ajax
application is a major feat

- The other challenge to using Ajax is browser support. In the past, this was a significant
concern, but today it’s rare to find a browser that doesn’t support the necessary
JavaScript features, even on mobile devices.

- ASP.NET is clever enough to use fallbacks when it encounters a browser that doesn’t
support Ajax (or has JavaScript switched off).

- Finally, Ajax applications introduce a few quirks that might not be to your liking. Web
pages that use Ajax often do a lot of work on a single page. This is different from
traditional web pages, which often move the user from one page to another to
complete a task.

- Although the multiple-page approach is a little more round about,it allows the user to
place bookmarks along the way and use the browser’s Back and Forward buttons to
step through the sequence.

- These techniques usually don’t work with Ajax applications, because there’s only a
single page to bookmark or navigate to, and the URL for that page doesn’t capture the
user’s current state.

Q5f. Give brief information on Accordion control with appropriate properties.

Ans:

- The Accordion is a container that stacks several panels on top of one another,and
allows you to view one at a time. Each panel has a header (which usually displays
a section title) and some content. When you click the header of one of the panels,
that panel is expanded and the other panels are collapsed, leaving just their
headers visible.
- Here’s an example that illustrates this structure by putting two AccordionPane
objects inside the Accordion:

<asp:Accordion ID = "Accordion1" runat = "server">


<Panes>
<asp:AccordionPane runat = "server">
</asp:AccordionPane>
<asp:AccordionPane runat = "server">
</asp:AccordionPane>
</Panes>
</asp:Accordion>

Ms. Ketaki Ghawali Page 26


Accordion Properties:

- SelectedIndex - The AccordionPane to be initially visible


- HeaderCssClass - Name of the CSS class to use for the headers. This can be either
applied to the Accordion as a default for all AccordionPanes, or an individual
AccordionPane.
- HeaderSelectedCssClass - Name of the CSS class to use for the selected header.
This can be either applied to the Accordion as a default for all AccordionPanes, or
an individual AccordionPane.
- ContentCssClass - Name of the CSS class to use for the content. This can be either
applied to the Accordion as a default for all AccordionPanes, or an individual
AccordionPane.
- FadeTransitions - True to use the fading transition effect, false for standard
transitions.
- TransitionDuration - Number of milliseconds to animate the transitions
- FramesPerSecond - Number of frames per second used in the transition
animations
- AutoSize - Restrict the growth of the Accordion. The values of the AutoSize
enumeration are described above.
- RequireOpenedPane - Prevent closing the currently opened pane when its header
is clicked (which ensures one pane is always open). The default value is true.
- SuppressHeaderPostbacks - Prevent the client-side click handlers of elements
inside a header from firing (this is especially useful when you want to include
hyperlinks in your headers for accessibility)
- Panes - Collection of AccordionPane controls
- HeaderTemplate - The Header template contains the markup that should be used
for an pane's header when databinding
- ContentTemplate - The Content template contains the markup that should be
used for a pane's content when databinding
- DataSource - The data source to use. DataBind() must be called.
- DataSourceID - The ID of the data source to use.
- DataMember - The member to bind to when using a DataSourceID

-----------------------------x---------------------------

Ms. Ketaki Ghawali Page 27

You might also like