AWP ATKT Solution Set April 2019 Ketaki Ghawali
AWP ATKT Solution Set April 2019 Ketaki Ghawali
(Information Technology)
(Semester V)
2018-19
Advanced Web
Programming
(USIT 503 Core)
University Paper Solution
By
Ms. Ketaki Ghawali
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.
- 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}};
- Pi()
- This method returns the pi value 3.14.
- myValue = Math.PI;
- 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
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.
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.
Console.WriteLine(x);
}
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";
}
ChangeReferenceType(std1);
Console.WriteLine(std1.StudentName);
}
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
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.
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:
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
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.
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:
Element Description
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.
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.
Question 3
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.
Ans:
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.
Ans:
Question 4
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.
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.
conn.Open();
Console.WriteLine("=============================");
while (reader.Read())
//Release resources
reader.Close();
conn.Close();
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.
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}" />
USING STYLES
- The GridView exposes a rich formatting model that’s based on styles.
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
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";
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.
@"App_Data\SuperProProductList.xml");
while (r.Read())
// Skip whitespace.
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();
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.
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
Ans:
- 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.
- 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:
- 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.
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:
-----------------------------x---------------------------