0% found this document useful (0 votes)
25 views32 pages

AWD - Notes

Uploaded by

dcruzsophia24
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)
25 views32 pages

AWD - Notes

Uploaded by

dcruzsophia24
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/ 32

Disclaimer

The attached PDF provides sample questions and answer guidelines as a reference only.
Actual exam questions may vary, though they may cover similar topics. Please use this as
supplementary material and review all relevant content.
Best of luck with your preparation!

UNIT I
1 What is namespace? Explain with the help of an example.
 These are the .NET way of providing containers for application code, such that code and
its contents may be uniquely identified.
 Namespaces are also used as a means of categorizing items in the .NET Framework.
 C# code, by default, is contained in the global namespace. This means that items contained
in this code are accessible from other code in the global namespace simply by referring to
them by name. You can use the namespace keyword, however, to explicitly define the
namespace for a block of code enclosed in curly brackets.
 Within a namespace, you can define nested namespaces, also using the namespace
keyword.
 After namespaces are set up, you can use the using statement to simplify access to the
names they contain.
 The System namespace is the root namespace for .NET Framework applications and
contains all the basic functionality you need for console applications. The System
namespace contains most of the basic types used in .NET applications.
 Creating a Namespace:
namespace my_namespace{
public class class_name{ … } }
 To conclude, all names defined in a .NET application, including variable names, are
contained in a namespace. Namespaces are hierarchical, and you often have to qualify
names according to the namespace that contains them in order to access them.

2 Write a program in C# to demonstrate multiple inheritance using interfaces. / Explain


the concept of inheritance
 Inheritance is one of the most important features of OOP.
 Any class may inherit from another, which means that it will have all the members of the
class from which it inherits. In OOP terminology, the class being inherited from (derived
from) is the parent class (also known as the base class).
 Classes in C# may derive only from a single base class directly, although of course that
base class may have a base class of its own, and so on.
 Inheritance enables you to extend or create more specific classes from a single, more
generic base class. For example, consider a class that represents a farm animal (as used by
ace octogenarian developer Old MacDonald in his livestock application). This class might
be called Animal and possess methods such as EatFood() or Breed(). You could create a
derived class called Cow, which would support all of these methods but might also supply
its own, such as Moo() and SupplyMilk(). You could also create another derived class,
Chicken, with Cluck() and LayEgg()methods.

ADVANCED WEB DEVELOPMENT


Code for multiple inheritance
// Define the first interface
interface IPrintable
{
void Print();
}

// Define the second interface


interface IDisplayable
{
void Display();
}

// Implementing multiple interfaces in a single class


class Document : IPrintable, IDisplayable
{
public void Print()
{
Console.WriteLine("Printing the document...");
}

public void Display()


{
Console.WriteLine("Displaying the document...");
}
}

class Program
{
static void Main()
{
// Create an object of Document class
Document doc = new Document();

// Call methods from both interfaces


doc.Print();
doc.Display();
}
}

ADVANCED WEB DEVELOPMENT


3 What is .NET Framework? Explain its architecture in brief. / Draw and explain .NET
Framework architecture.
 The .NET Framework is a revolutionary platform created by Microsoft for developing
applications.
 The .NET Framework consists primarily of a gigantic library of code that you use from
your client languages (such as C#) using object-oriented programming (OOP) techniques.
This library is categorized into different modules — you use portions of it depending on
the results you want to achieve. For example, one module contains the building blocks for
Windows applications, another for network programming, and another for Web
development.
 Part of the .NET Framework library defines some basic types. A type is a representation of
data, and specifying some of the most fundamental of these (such as ‘‘a 32-bit signed
integer’’) facilitates interoperability between languages using the .NET Framework. This is
called the Common Type System (CTS).
 As well as supplying this library, the .Net Framework also includes the .NET Common
Language Runtime (CLR), which is responsible for maintaining the execution of all
applications developed using the .NET library.
 When you compile code that uses the .NET Framework library, you don’t immediately
create operating-system-specific native code. Instead, you compile your code into Common
Intermediate Language (CIL) code. This code isn’t specific to any operating system (OS)
and isn’t specific to C#.
 Just-in-time (JIT) compiler, which compiles CIL into native code that is specific to the OS
and machine architecture being targeted. Only at this point can the OS execute the
application.
 Code written using the .NET Framework is managed when it is executed (a stage usually
referred to as runtime). This means that the CLR looks after your applications by managing
memory, handling security, allowing cross-language debugging, and so on.
 One of the most important features of managed code is the concept of garbage collection.
This is the .NET method of making sure that the memory used by an application is freed
up completely when the application is no longer in use.

ADVANCED WEB DEVELOPMENT


4 What is C#? Explain variables and datatype in C#
 C# is a block-structured language, meaning statements are part of a block of code. These
blocks, which are delimited with curly brackets ({ and }), may contain any number of
statements, or none at all. C# code is made up of a series of statements, each of which is
terminated with a semicolon.
 C# code is made up of a series of statements, each of which is terminated with a semicolon.
 For example, a simple block of C# code could take the following form:
{
Statement1;
Statement2;
}
 Blocks of code may be nested inside each other (that is, blocks may contain other blocks
 Variables are concerned with the storage of data.
 To use variables, you have to declare them. This means that you have to assign them a name
and a type. After you have declared variables, you can use them as storage units for the type
of data that you declared them to hold.
 C# syntax for declaring variables merely specifies the type and variable name:
<type><name>;
 The basic variable naming rules are as follows:
 The first character of a variable name must be either a letter, an underscore character (_),
or the at symbol (@).
 Subsequent characters may be letters, underscore characters, or numbers.
 Keywords such as using and namespace should not be used as variable name

ADVANCED WEB DEVELOPMENT


5 Distinguish between inheritance and abstract classes.
Feature Inheritance Abstract Classes
Enables code reuse and a Serves as a blueprint with some
Purpose
hierarchical relationship unimplemented methods
Classes in an inheritance
Instantiation hierarchy can be instantiated if Cannot be instantiated directly
not abstract
May contain fully implemented Can contain both abstract
Contains
methods, but usually used to share (unimplemented) and concrete
Implementations
behavior across child classes (implemented) methods
Usage with A class can inherit multiple Abstract classes can implement
Interfaces interfaces but only one base class interfaces and be inherited
When a clear “is-a” relationship When some methods need to be
Use Cases exists between classes (e.g., Dog defined by subclasses while sharing
is an Animal) some common functionality

6 Define the accessibility modifiers: public, private, protected, internal, and protected
internal.
 Private members of the base class are not accessible from a derived class, but public
members are. However, public members are accessible to both the derived class and
external code. Therefore, if you could use only these two levels of accessibility, you
couldn’t have a member that was accessible both by the base class and the derived class
but not external code.
 To get around this, there is a third type of accessibility, protected, in which only derived
classes have access to a member. As far as external code is aware, this is identical to a
private member — it doesn’t have access in either case
 Public: Accessible from anywhere within the same assembly or another assembly.
 Private: Accessible only within the same class or struct.
 Protected: Accessible within the same class or a derived class.
 Internal: Accessible only within the same assembly, but not from another assembly.
 Protected Internal: Accessible within the same assembly or from derived classes in
another assembly.
 Private Protected: Accessible within the same class or derived classes within the same
assembly.
 Create example of your own

ADVANCED WEB DEVELOPMENT


7 Explain various types of constructors in C#.
 At times you will want to perform additional tasks during an object’s initialization stage,
such as initializing the data stored by an object. A constructor is what you use to do this.
 All class definitions contain at least one constructor. These constructors may include a
default constructor, which is a parameterless method with the same name as the class itself.
A class definition might also include several constructor methods with parameters, known
as nondefault constructors.
 In C#, constructors are called using the new keyword. For example, you could instantiate a
CupOfCoffee object using its default constructor in the following way:
CupOfCoffee myCup = new CupOfCoffee();
 Objects may also be instantiated using nondefault constructors. For example, the
CupOfCoffee class might have a nondefault constructor that uses a parameter to set the
bean type at instantiation: CupOfCoffee myCup = new CupOfCoffee("Blue Mountain");
 A static constructor can never be called directly; instead, it is executed when one of the
following occurs:
1. An instance of the class containing the static constructor is created.
2. A static member of the class containing the static constructor is accessed
 Constructors, like fields, properties, and methods, may be public or private. Code external
to a class can’t instantiate an object using a private constructor; it must use a public
constructor.

8 What is an assembly? Explain the difference between public and private assembly.
 When you compile an application, the CIL code created is stored in an assembly.
Assemblies include both executable application files that you can run directly from
Windows without the need for any other programs (these have a .exe file extension) and
libraries (which have a .dll extension) for use by other applications.
 In addition to containing CIL, assemblies also include meta information and optional
resources. The meta information enables assemblies to be fully self-descriptive.
 Of course, you won’t necessarily want to include everything required to run an application
in one place. You might write some code that performs tasks required by multiple
applications. In situations like that, it is often useful to place the reusable code in a place
accessible to all applications. In the .NET Framework, this is the global assembly cache
(GAC). Placing code in the GAC is simple — you just place the assembly containing the
code in the directory containing this cache.
 Types of Assemblies:
1. Private Assembly: Used by a single application, stored in the application's directory.
2. Shared Assembly: Used by multiple applications, stored in the Global Assembly Cache
(GAC).

ADVANCED WEB DEVELOPMENT


9 Write a short note on value and reference types.
 Data in C# is stored in a variable in one of two ways, depending on the type of the variable.
This type will fall into one of two categories: reference or value. The difference is as
follows:
1. Value types store themselves and their content in one place in memory.
2. Reference types hold a reference to somewhere else in memory (called the heap) where
content is stored.
 One key difference between value types and reference types is that value types always
contain a value, whereas reference types can be null, reflecting the fact that they contain no
value.
Here’s a clear, tabular summary of the differences between value types and reference types:
Feature Value Types Reference Types
Stores a reference (address) to
Storage Stores actual data directly in memory
data in memory
Assignment Copies the actual data to a new memory Copies the reference (points to
Behavior location the same data)
Memory
Typically allocated on the stack Typically allocated on the heap
Allocation
Primitive types (int, float, bool), structs in Objects, arrays, lists,
Examples
C#, non-object types in Python dictionaries, classes
Generally slower due to
Performance Generally faster due to direct data access
dereferencing
Garbage Often necessary due to heap
Not usually necessary as data is on the stack
Collection allocation

10 Explain for each loop


 The foreach loop in C# is a simple way to go through each item in a collection, like an array
or list. It’s helpful when you just need to read each item, without needing to know its
position in the collection.
 Syntax:
foreach (var item in collection)
{
// Code to use each item
}
 Example:
using System;
class Program {
static void Main() {
int[] numbers = { 1, 2, 3, 4, 5 }; // Create an array of numbers
Console.WriteLine("Numbers in the array:");
foreach (int num in numbers) {
Console.WriteLine(num); // Print each number }}}

ADVANCED WEB DEVELOPMENT


11 Write a sample C# program to demonstrate class, object, and method call. Use
comments wherever required.
using System;
namespace SampleProgram
{
// Define a class named `Person`
class Person
{
// Declare fields (attributes) for the Person class
public string Name; // Name of the person
public int Age; // Age of the person
// Define a method to display person details
public void DisplayInfo()
{
Console.WriteLine("Name: " + Name);
Console.WriteLine("Age: " + Age);
}
// Define a method to set the age of the person
public void SetAge(int age)
{
Age = age;
}
}
class Program
{
static void Main(string[] args)
{
// Create an object (instance) of the Person class
Person person1 = new Person();
// Set attributes of the person using the object
person1.Name = "Alice";
person1.SetAge(25); // Call the SetAge method to assign age
// Call the DisplayInfo method to print person details
person1.DisplayInfo();
// Create another object of the Person class
Person person2 = new Person();
person2.Name = "Bob";
person2.SetAge(30);
// Call DisplayInfo method for the second object
person2.DisplayInfo();
}
}
}

ADVANCED WEB DEVELOPMENT


UNIT II
1. Explain any five properties of ListBox and DropDownList controls.

ADVANCED WEB DEVELOPMENT


2. Explain AdRotator control with an example. / Write a note on AdRotator control.
 The AdRotator is to provide a graphic on a page that is chosen randomly from a group of
possible images. Every time the page is requested an image is selected at random and
displayed which is the “rotation” indicated by the name Adrotator.
 One use of Adrotator is to show banner style advertisements on a page but we can use it
any time we want to vary an image randomly.
 The Advertisment file
 The AdRotator stores its list of image files in an XML file. This file uses the format shown
here:
<Advertisements>
<Ad>
<ImageUrl>proetech.jpg<ImageUrl>
<NavigateUrl>http://www.prosetech.com<NavigateUrl>
<AlternateText><ProseTech Site</Alternate text>
<Impressions>1</Impressions>
<Keyword>Computer</Keyword>
</Ad>
</Advertisements>
 Advertisement File Elements
1. ImageUrl - The path of image that will be displayed.
2. NavigateUrl - The link that will be followed when the user clicks the ad.
3. AlternateText - The text that will be displayed instead of the picture if it cannot be
displayed.
4. Keyword - Keyword identifying a group of advertisements. This is used for filtering.
5. Impressions - The number indicating how often an advertisement will appear.
 The AdRotator class
 The actual AdRotator class provides a limited set of properties
1. _blank :- The link opens a new unframed window.
2. parent :- The link opens in the parent of the current frame.
3. _self :- The link opens in the current frame
4. _top :- The link opens in the topmost frame of the current window.

ADVANCED WEB DEVELOPMENT


3. List and explain any four types of validation controls used in ASP.NET. / What is the
purpose of validation controls? List and explain the use of validation controls
available in ASP.NET.
 Validation controls are used to implement presentation logic, to validate user input data and
it is also used for data format, data type and data range.
 Validation controls in ASP.NET There are six types of validation controls in ASP.NET
1. Required Field Validation Control
2. Compare Validator Control
3. Range Validator Control
4. Regular Expression Validator Control
5. Custom Validator Control
 The RequiredFieldValidator control is simple validation control, which checks to see if the
data is entered for the input control. We can have a RequiredFieldValidator control for each
form element on which you wish to enforce Mandatory Field rule.
 Syntax:-


 The CompareValidator control allows us to make comparison to compare data entered in
an input control with a constant value or a value in a different control.
 Syntax:-


 The RangeValidator control verifies that the input value falls within a predetermined range.
 Syntax:-


 The RequiredExpressionValidator allows validating the input text by matching against a
pattern of regular expression.
 Syntax:-


 The CustomValidator control allows writing application specific custom validation routines
for both the client side and the server side validation.
 Syntax:-

ADVANCED WEB DEVELOPMENT


4. Explain Calendar control with an example in ASP.NET.
 The calendar control is used to display a calendar in the browser. This control displays a
one month calendar that allows the user to select dates and move to the next and previous
months.
 It is a functionality rich web control which provides displaying one month at a time,
selecting a day, a week or a month, selecting a range of days moving from month to month
and controlling the display of the days programmatically.
 Syntax:


 Properties of Calendar:
1. SelectedDate: Gets or sets the selected date.
2. SelectedDates: Gets a collection of Date Time objects representing the selected dates.
3. VisibleDate: Gets or sets the date that specifies the month to display
 Events:
1. SelectionChanged It is raised when a day, a week or an entire month is selected

5. List and describe the various file types used in an ASP.NET application.
 .aspx- This file is basically an extension of ASP.NET Web Pages. It is used for web form
pages.
 .ascx – This extension is basically used for web form user controls. The .ascx extension is
often used for consistent parts of a website like headers, footers etc.
 .asmx – This extension is used for files that implement ASP.NET Web Services.
 .vb – This extension is used for VisualBasic.NET code modules. These files are code-
behind files and are used to separate code from user interface.
 .resx – These files are basically used for Windows Form Application for storing resources
such as text strings for internationalization of applications.
 Global.asax – These files are basically used to define Applicationand-Session level
variables and start up procedures.

6. What is a view state? Give advantages and disadvantages.


 View State is a mechanism in ASP.NET that maintains the state of server-side controls
between postbacks by storing data in a hidden field on the page.
 Advantages:
1. No server resources
2. Ensures security
3. Simple and Easy to use
 Disadvantage:
1. Large data may cause page load problem
2. Does not transfer information from page to page
 Storing value: ViewState["KeyName"] = "SomeValue";
 Retrieving value:
string value = ViewState["KeyName"] as string;
if (value != null) {
Response.Write($"Stored Value: {value}"); }

ADVANCED WEB DEVELOPMENT


7. Write a short note on Page class. / Write a note on Page class.
 Every web Page is a custom class that inherits from the system. web.UI.Page control.
 By inheriting form this class, your page class acquires a number of properties that our code
can use. These include properties for enabling caching, validation and tracing.
 Some fundamental properties of page class are as follows:-

8. Explain the need for user control. How is it created and used?
 User controls behaves like a miniature ASP.NET pages and webforms which could be used
by many other pages.
 These are derived from the System.Web.UI.UserControl Class. These controls have the
following characteristics:
• They have an .ascx extension.
• They may not contain any <HTML>, <BODY>, or <FORM> Tags.
• They have a Control directive instead of a Page directive.
 To understand the concept, let us create a simple user control, which will work as footer for
the web pages. To create and use the user control, take the following steps:
1. Create a new web application.
2. Right click on the project folder on the Solution Explorer and choose Add New Item.
3. Select Web User Control from the Add New Item dialog box and name it footer.ascx.
Initially, the footer.ascx contains only a Control directive. (footer.ascx)
4. To add the user control to your web page, you must add the Register directive and an
instance of the user control to the page.
 <%@ Register Src="~/footer.ascx" TagName="footer" TagPrefix="Tfooter" %>

ADVANCED WEB DEVELOPMENT


9. Explain SiteMapPath control in ASP.NET.
 Site maps are XML files which are mainly used to describe the logical structure of the web
application.
 It defines the layout of all pages in web application and how they relate to each other.
 Whenever you want you can add or remove pages to your site map there by managing
navigation of website efficiently. Site map files are defined with .sitemap extension.
 Element is the root node of the sitemap file.
 It has three attributes:
• Title: It provides textual description of the link.
• URL: It provides the location of the valid physical file.
• Description: It is used for tooltip of the link.
 Properties of SiteMapPath Control:
 • PathSeparator: This property is to get or set the out separator text.
 Creation of Site Map Below is the HTML Markup of the Master Page Main.Master that
contains the SiteMapPath control as well as the SiteMapDataSource control.

10. Write a short note on List controls in ASP.NET. / What is the difference between
ListBox and Drop Down List? List and explain any three common properties of these
controls.
 These controls are used to display the list with some list items in the page. These controls
include List Box, Drop Down List, Check Box List, Radio Button List and Bulleted List.
 ListBox: We can select multiple items from ListBox at a time.
 Basic syntax of list box control:


 DropDownList control is used select single option from multiple listed items.
 Basic syntax of DropDown

ADVANCED WEB DEVELOPMENT


 Common properties of List Box and Drop Down List are as follows


 The CheckBox control allows the user to set true/false or yes/no type options. The user can
select or deselect it. When a check box is selected it has the value True, and when it is
cleared, it holds the value False.
 Properties of CheckBox Control:
1. AutoCheck: Gets or sets a value indicating whether the Checked or CheckedState value
and the appearance of the control automatically change when the check box is selected
2. Checked: Gets or sets a value indicating whether the check box is selected.
3. CheckState; Gets or sets the state of a check box.
4. Text: Gets or sets the caption of a check box.
 Radio Button List Control is same as Drop Down List but it displays a list of radio buttons
that can be arranged either horizontally or vertically. We can select only one item from the
given Radio Button List of options.
 The bulleted list control creates bulleted lists or numbered lists.

ADVANCED WEB DEVELOPMENT


UNIT III
1. Explain exception handling mechanism in C# with key features.
 A C# exception is a response to an exceptional circumstance that arises while a program is
running, such as an attempt to divide by zero.
 C# exception handling is built upon four keywords: try, catch, finally and throw. –
• try - A try block identifies a block of code for which particular exceptions is activated. It
is followed by one or more catch blocks.
• catch - A program catches an exception with an exception handler at the place in a program
where you want to handle the problem. The catch keyword indicates the catching of an
exception.
• finally - The finally block is used to execute a given set of statements, whether an
exception is thrown or not thrown. For example, if you open a file, it must be closed whether
an exception is raised or not.
• throws - A program throws an exception when a problem shows up. This is done using a
throw keyword.
 try
{
// Risky code goes here (opening a file, connecting to a database, and so
on).
}
catch
{
// An error has been detected. You can deal with it here.
}
finally
{
// Time to clean up, regardless of whether or not there was an error.
}
 Every exception class derives from the base class System.Exception. The .NET Framework
is full of predefined exception classes, such as NullReferenceException, IOException,
SqlException, and so on.
 if (divisor != 0)
{
// It's safe to divide some number by divisor.
}
if (System.IO.File.Exists("myfile.txt"))
{
// You can now open the myfile.txt file.
// However, you should still use exception handling because a variety of
// problems can intervene (insufficient rights, hardware failure, etc.).
}

ADVANCED WEB DEVELOPMENT


2. How is information transferred between pages?
 These are the Response objects of Asp.Net which are used to redirect page from one page
to another page and true and false are the optional parameters of the Redirect methods
which decides whether the current page response terminate or not.
 Response.Redirect method takes the following parameter
1. Url (string): This is a string parameter in which url or page name is given that helps to
navigate from one page to another page.
2. EndResponse (Boolean): EndResponse is the optional parameter of the Redirect method
having true and false values, when you false value then it does not terminate the execution
of the current page, the default is true.
 Syntax: Response.Redirect("Default.aspx"); •
 Syntax: Response.Redirect("Default.aspx", false);
 Response.Redirect("Default.aspx", true);
 Both Response.Redirect and Server.Transfer methods are used to transfer a user from one
web page to another web page. Both methods are used for the same purpose but still there
are some differences as follows.
 The Response.Redirect method redirects a request to a new URL and specifies the new
URL while the Server.Transfer method for the current request, terminates execution of the
current page and starts execution of a new page using the specified URL path of the page.
Both Response.Redirect and Server.Transfer has the same syntax like:
1. Response.Redirect("UserDetail.aspx");
2. Server.Transfer("UserDetail.aspx");

ADVANCED WEB DEVELOPMENT


3. What are state management techniques in ASP.NET?
 The State Management techniques are classified into two categories


 In client-side state management, data is stored on the client's browser, making it accessible
across multiple requests without relying on the server.
1. View State: Stores data in a hidden field on a webpage. It maintains the state of the controls
between postbacks within the same page.
2. Control State: Similar to View State but is specifically used to preserve critical information
for controls. Even if View State is disabled, Control State ensures essential data is retained.
3. Hidden Fields: Stores data in HTML hidden input fields that are sent back and forth
between the client and server with each postback. These are not visible to users but can be
accessed via code.
4. Cookies: Small pieces of data stored on the client’s machine. Cookies are commonly used
to store user preferences, session information, or authentication tokens. They have an
expiration date and can persist across sessions.
5. Query Strings: Passes data via the URL. Useful for passing small amounts of data between
pages. However, query strings have size limitations and are visible to users, posing security
risks for sensitive data.
 Server-side state management stores data on the server, offering better security and control
but may impact server resources.
1. Application State: Stores data that is shared across all sessions and users of an application.
Useful for storing application-wide data that does not change frequently, such as application
settings.
2. Session State: Stores data unique to each user session. It is maintained throughout the user's
interaction with the application and can be used to track user-specific information like
shopping cart contents.
3. Profile Properties: Allows personalization by storing user-specific information that
persists across sessions. Profile properties are commonly used for data such as user
preferences and settings.

ADVANCED WEB DEVELOPMENT


4. Elaborate cookies with suitable code snippet.
 A cookie is a small piece of information stored on the client machine.
 This file is located on client machines "C:\Document and Settings\Currently_Login
user\Cookie" path.
 It is used to store user preference information like Username, Password, City and Phone
No etc. on client machines.
 We need to import namespace called Systen.Web.HttpCookie before we use cookie
 Types of Cookies:
1. Persist Cookie - A cookie has not had expired time which is called as Persist Cookie
2. Non-Persist Cookie - A cookie has expired time which is called as Non-Persist Cookie
 Creation of cookies: It’s really easy to create a cookie in the Asp.Net with help of Response
object or HttpCookie
HttpCookie userInfo = new HttpCookie("userInfo");
userInfo["UserName"] = "abc";
userInfo["UserColor"] = "Black";
userInfo.Expires.Add(new TimeSpan(0, 1, 0));
Response.Cookies.Add(userInfo);
 Retrieve from cookie: Its easy way to retrieve cookie value form cookies by help of Request
object.
string User_Name = string.Empty;
string User_Color = string.Empty;
User_Name = Request.Cookies["userName"].Value;
User_Color = Request.Cookies["userColor"].Value;
 Cookie's common property:
1. Domain: This is used to associate cookies to domain.
2. Secure: We can enable secure cookie to set true (HTTPs).
3. Value: We can manipulate individual cookie.
4. Values: We can manipulate cookies with key/value pair.
5. Expires: Which is used to set expire date for the cookies.
 Advantages of Cookie:
• Its clear text so user can able to read it.
• We can store user preference information on the client machine.
• Its easy way to maintain.
• Fast accessing.
 Disadvantages of Cookie
• If user clears cookie information we can't get it back.
• No security.
• Each request will have cookie information with page.

ADVANCED WEB DEVELOPMENT


5. Explain Master Page with its uses and working.
 ASP.NET master pages allow us to create a consistent layout for the pages in our
application.
 A single master page defines the look and feel and standard behavior that we want for all
of the pages (or a group of pages) in our application.
 We can then create individual content pages that contain the content we want to display.
 When users request the content pages, they merge with the master page to produce output
that combines the layout of the master page with the content from the content page.
 Master pages actually consist of two pieces, the master page itself and one or more content
pages.
 Uses:
1. Ensures consistent layout across pages (e.g., header, footer).
2. Promotes code reusability by defining common elements once.
3. Eases maintenance; updates in one place reflect on all pages.
4. Improves development workflow by separating layout and content.

6. How is the connection between the content page and the master page established?
 Master page provides a framework (common content as well as the layout) within which
the content from other pages can be displayed. It provides elements such as headers, footers,
style definitions, or navigation bars that are common to all pages in your web site.
 So the Content Pages need not have to duplicate code for shared elements within your Web
site.
 It gives a consistent look and feel for all pages in your application.
 The master page layout consists of regions where the content from each content page should
be displayed. These regions can be set using ContentPlaceHolder server controls.
 These are the regions where you are going to have dynamic content in your page
 A derived page also known as a content page is simply a collection of blocks the runtime
will use to fill the regions in the master.
 To provide content for a ContentPlaceHolder, you use another specialized control, called
Content.
 The ContentPlaceHolder control and the Content control have a one-to-one relationship.
 For each ContentPlaceHolder in the master page, the content page supplies a matching
Content control
 ASP.NET links the Content control to the appropriate ContentPlaceHolder by matching the
ID of the ContentPlaceHolder with the Content ContentPlaceHolderID property of the
corresponding Content control.

ADVANCED WEB DEVELOPMENT


UNIT IV

1. Explain the SQL Data Provider model.


 ADO.NET provides common way to interact with data sources, but comes in different sets
of libraries for each we can talk to a data source. These libraries are called Data Providers
and usually named for the protocol or data source type they allow us to interact with.
 Following table shows some well known data providers, the API prefix they use:

2. Explain the ADO .NET architecture. / List and explain ADO.NET objects.
 ADO (ActiveX Data Object) is the database access technologies including components for
retrieving data, storing data in memory and binding data to controls.
 It is an Object Oriented set of libraries that allows us to interact with data source.
 The data source can be a database, text file, Excel spreadsheet or an XML file.

ADVANCED WEB DEVELOPMENT


 Connection: The first important component is the connection object. The connection object
is required to connect with your backend database which can be SQL Server, Oracle,
MySQL, etc. To create a connection object, you need at least two things. The first one is
where is your database located i.e. the Machine name or IP Address or someplace where
your database is located. And the second thing is the security credentials i.e. whether it is a
windows authentication or user name and password-based authentication. So, the first is to
create the connection object and the connection is required to connect to the backend data
source.
 Command: The second important component is the command object. When we talk about
databases like SQL Server, Oracle, MySQL, then understand SQL. The command object is
the component where you go and write your SQL queries. Later you take the command
object and execute it over the connection. Then you can fetch data or send data to the
database using the command object and SQL queries.
 Data Reader: Data Reader is a read-only connected record set that helps us to read the
records only in the forward mode. Here, you need to understand three things i.e. read-only,
connected, and forward mode.
 DataSet: It is a disconnected recordset that can be browsed in both i.e. forward and
backward. It is also possible to update via dataset. DataSet gets filled by somebody called
DataAdapter.
 DataAdapter: The DataAdapter acts as a bridge between the command object and the
dataset. What the DataAdapter does, it takes the data from the command object and fills the
data set.
 DataView: A DataView enables you to create different views of the data stored in a
DataTable, a capability that is often used in data-binding applications. Using a DataView,
you can expose the data in a table with different sort orders, and you can filter the data by
row state or based on a filter expression.

3. What is the use of data source control? Explain the various types of data sources in
ASP.NET. / Write a short note on Data Source controls.
 A data source control interacts with the data-bound controls and hides the complex data
binding processes. These are the tools that provide data to the data bound controls and
support execution of operations like insertions, deletions, sorting, and updates.
 The data source controls used for hierarchical data are:
 XMLDataSource - It allows binding to XML files and strings with or without schema
information.
 SiteMapDataSource - It allows binding to a provider that supplies site map information.
 The data source controls used for tabular data are:
 SqlDataSource: It represents a connection to an ADO.NET data provider that returns
SQL data, including data sources accessible via OLEDB and ODBC.
 ObjectDataSource: It allows binding to a custom .Net business object that returns data.
 LinqdataSource: It allows binding to the results of a Linq-to-SQL query (supported by
ASP.NET 3.5 only).
 AccessDataSource: It represents connection to a Microsoft Access database.

ADVANCED WEB DEVELOPMENT


4. Explain SqlDataSource in ADO.NET.
 The SqlDataSource control represents a connection to a relational database such as SQL
Server or Oracle database, or data accessible through OLEDB or Open Database
Connectivity (ODBC). Connection to data is made through two important properties
ConnectionString and ProviderName.
 The following code snippet provides the basic syntax of the control:

 The following table provides the related sets of properties of the SqlDataSource control,
which provides the programming interface of the control:

ADVANCED WEB DEVELOPMENT


5. What is a GridView control? Explain with an example.
 The GridView control displays the values of a data source in a table. Each column
represents a field, while each row represents a record.
 The GridView control supports the following features:
1. Binding to data source controls, such as SqlDataSource.
2. Built-in sort capabilities.
3. Built-in update and delete capabilities. Data Controls
4. Built-in paging capabilities.
5. Built-in row selection capabilities.
6. Multiple data fields for the hyperlink columns.
7. Customizable appearance through themes and styles.
 Creating a GridView:
<asp:GridView ID="gridService" runat="server">
</asp:GridView>
 Properties of GridView:

6. Differentiate between Direct and Indirect Data Access


Feature Connected Architecture Disconnected Architecture
Maintains a full-time connection Connects only when reading or updating
Connection State
between database and app data
Main Primarily uses SqlDataAdapter and
Primarily uses DataReader
Components DataSet
Bi-directional (data can be modified
Directionality Forward-only
offline)
Allows editing, inserting, and deleting
Data Access Read-only access
records
Data Storage No temporary data storage Uses DataSet as temporary storage
Suitable for quick data retrieval and Ideal for disconnected or offline
Usage
processing processing
Connection DataAdapter manages connection
Direct connection with database
Handling establishment and termination

ADVANCED WEB DEVELOPMENT


7. Differentiate between FormView and DetailsView in ASP.NET.
DetailsView Control
 Purpose: Used to display a single database record at a time in a table layout.
 Features:
o Supports displaying, inserting, updating, and deleting records.
o Works well for basic layouts where each field is displayed in a two-column table (label
and value).
o Limited layout customization but easy to set up.
 Example Steps:
1. Create a new web application in Visual Studio.
2. Add a DetailsView control to the webpage.
3. Create a SQL Server database and a table (e.g., UserMst with fields ID, Name, City).
4. Connect to the database in the application.
5. Bind data to the DetailsView control to display records.
FormView Control
 Purpose: Displays a single record with more layout flexibility, allowing the use of
templates.
 Features:
o Supports custom layouts, making it ideal for more complex forms.
o Allows the use of ItemTemplate for display and EditItemTemplate for editing.
o Great for custom designs where you can place fields and controls in any arrangement.
 Example Steps:
1. Create a SQL Server table (e.g., StudentsResult with fields like RollNumber,
StudentName, etc.).
2. Add a FormView control to the webpage and design it with templates.
3. Bind data using a stored procedure (e.g., spGetStudentResult) to pull records from the
table.

ADVANCED WEB DEVELOPMENT


UNIT V

1. Explain the concept of authentication and authorization.


 Authentication is the process of verifying the identity of a user. In ASP.NET, it ensures that
the application knows who is accessing it. Once a user’s identity is confirmed, they are
given an authentication token or cookie that maintains their identity during their session.
 Types of Authentication in ASP.NET:
1. Forms Authentication:
 Designed for web applications, Forms Authentication requires users to log in with
credentials (like username and password) on a login page. Once authenticated, ASP.NET
assigns an authentication cookie that identifies the user for future requests. This approach
is commonly used in traditional ASP.NET Web Forms applications.
2. Windows Authentication:
 Useful in intranet environments where users are already authenticated through their
Windows credentials. ASP.NET relies on Internet Information Services (IIS) to authenticate
users based on their Windows login information.
3. Cookie-Based Authentication:
 A traditional method in which users are identified through cookies stored in their browser.
When users log in, the server creates an encrypted cookie that is sent with every request to
maintain their authenticated status. This method is often used in conjunction with Forms
Authentication.
 Authorization in ASP.NET defines what a user is allowed to do after they have been
authenticated. It is the process of granting or denying users permission to access resources
or perform actions within the application.
 Types of Authorization in ASP.NET:
1. Role-Based Authorization:
 The most common approach, where users are assigned roles (e.g., Admin, User, Manager)
that determine what they can access. ASP.NET checks the user’s roles before granting
access to specific resources. This approach simplifies managing access for groups of users,
as permissions are tied to roles rather than individual users.
2. Policy-Based Authorization:
 Allows more granular control by defining policies based on custom rules. Policies can
combine multiple requirements (e.g., roles, claims, or custom criteria) to determine access.
This is useful for more complex scenarios where specific conditions need to be met, like
granting access only if a user has a particular role and meets an additional condition.
3. Claims-Based Authorization:
 An alternative to role-based authorization that uses claims—pieces of information about
the user, like their age, email, or job title.
 Claims-based authorization is flexible, allowing access decisions based on more than just
roles.
 ASP.NET applications can use claims to create fine-grained authorization rules, particularly
in applications where user identity attributes play a role in access decisions.

ADVANCED WEB DEVELOPMENT


2. Write a note on Nuget Package.
 NuGet is the package manager for .NET that makes it easy to add, update, and manage
libraries in your .NET applications. It allows you to integrate third-party libraries and tools
into your .NET projects efficiently
 Installing NuGet in Visual Studio
 NuGet is integrated into Visual Studio, so if you’re using a recent version of Visual Studio,
it comes pre-installed. However, you can also use the NuGet CLI if you’re working outside
Visual Studio or if you prefer the command line.
 Visual Studio Installation
1. Open Visual Studio Installer.
2. Make sure the .NET desktop development workload is installed, as it includes NuGet
support.
3. If NuGet isn’t available for some reason, you can add it by installing the NuGet
Package Manager through Visual Studio’s Extensions and Updates window.
 Installing the NuGet CLI
1. If you prefer using the CLI, you can download and install the NuGet CLI:
2. Download the NuGet executable from NuGet.org.
3. Add the location of nuget.exe to your environment’s PATH to run it from anywhere in
the command line.
 Package Manager Console
 In Visual Studio, you also have access to the Package Manager Console, where you can
run NuGet commands directly.
 Working with NuGet in Visual Studio
 Adding a Package
1. Right-click the References or Dependencies node in Solution Explorer and select
Manage NuGet Packages.
2. In the NuGet Package Manager window:
3. Use the Browse tab to search for packages on NuGet.org.
4. Click on a package and select Install.
5. Review and accept any license agreements.
 Updating a Package
1. Open Manage NuGet Packages for your project.
2. Select the Updates tab to view packages with newer versions available.
3. Select the package you want to update and click Update.
 Removing a Package
1. Open Manage NuGet Packages for your project.
2. In the Installed tab, select the package you want to remove.
3. Click Uninstall.

ADVANCED WEB DEVELOPMENT


3. Explain what Bootstrap is.
 Bootstrap provides a wide range of pre-designed UI components like navigation bars,
buttons, cards, forms, and modals, along with a powerful grid system for layout control. It
allows you to build responsive websites quickly with minimal custom CSS.
 To use Bootstrap, you need to include the CSS and JavaScript files in your project. You can
either download Bootstrap and link the files locally or use a Content Delivery Network
(CDN) link.
 Adding Bootstrap via CDN
 Include the following links in the <head> section of your HTML file:
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
 Bootstrap’s structure typically follows the HTML5 structure with some key Bootstrap-
specific classes. Here’s a basic layout:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Page</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-
target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-
label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
</div>

ADVANCED WEB DEVELOPMENT


</nav>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></scri
pt>
</body>
</html>
 Bootstrap offers classes to style various text elements, providing a modern, consistent
appearance across different devices.
 Common Typography Classes
 Headings: Bootstrap provides classes for headings (.h1, .h2, etc.), making it easy to adjust
font size.
<h1 class="h1">Heading 1</h1>
<h2 class="h2">Heading 2</h2>
 Display Headings: For larger headings, use .display-1, .display-2, etc.
<h1 class="display-1">Display 1</h1>
<h2 class="display-2">Display 2</h2>
 Text Utilities: Bootstrap provides utility classes for text alignment, color, and formatting.
 html
<p class="text-center">Centered Text</p>
<p class="text-primary">Primary colored text</p>
<p class="text-uppercase">Uppercase Text</p>
 Blockquotes: Styled blockquotes are easy with .blockquote.
<blockquote class="blockquote">
<p class="mb-0">This is a blockquote.</p>
<footer class="blockquote-footer">Someone famous</footer>
</blockquote>
 Bootstrap makes it easy to create beautiful, responsive forms with minimal effort. Forms
are structured with <form>, <input>, and <label> elements, enhanced by Bootstrap’s
classes.
 Basic Form Example
<form class="container mt-4">
<div class="mb-3">
<label for="exampleInputEmail" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail" >
</div>
<div class="mb-3">
<label for="exampleInputPassword" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword">
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

ADVANCED WEB DEVELOPMENT


4. What is AJAX? Explain Partial Refreshes and Progress Notifications.
 AJAX (Asynchronous JavaScript and XML) is a powerful technology used to create
dynamic web applications by enabling parts of a page to be updated without a full page
reload. ASP.NET supports AJAX with built-in features like the AJAX Control Toolkit,
which provides ready-to-use controls to streamline AJAX-based functionality.
1. Using Partial Refreshes
Partial refreshes let you update specific parts of a page without reloading the whole page. In
ASP.NET, you can implement this easily using the UpdatePanel control. The UpdatePanel
works with the ScriptManager to perform asynchronous postbacks, refreshing only the section
inside the panel.
Example: Using UpdatePanel for Partial Refresh
To create a partial refresh:
1. Place the content you want to update inside an UpdatePanel.
2. Add a trigger for an event (like a button click) to perform the partial update.
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:Label ID="TimeLabel" runat="server" Text="Current time will appear here" />
<asp:Button ID="RefreshButton" runat="server" Text="Refresh Time"
OnClick="RefreshButton_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RefreshButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
In the code-behind, set the RefreshButton_Click event:
protected void RefreshButton_Click(object sender, EventArgs e)
{
TimeLabel.Text = DateTime.Now.ToString("HH:mm:ss");
}
When you click Refresh Time, only TimeLabel updates, rather than the whole page, thanks to
the UpdatePanel.
2. Using Progress Notifications
A progress notification can improve user experience by showing a loading message or spinner
while AJAX requests are being processed. In ASP.NET, the UpdateProgress control displays
a loading indicator for any ongoing asynchronous postback in the associated UpdatePanel.
Example: Using UpdateProgress
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:Label ID="DataLabel" runat="server" Text="Data will load here." />
<asp:Button ID="LoadButton" runat="server" Text="Load Data"
OnClick="LoadButton_Click" />
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress AssociatedUpdatePanelID="UpdatePanel1" runat="server">


<ProgressTemplate>
<div class="loader">Loading...</div>

ADVANCED WEB DEVELOPMENT


</ProgressTemplate>
</asp:UpdateProgress>
In the code-behind:
protected void LoadButton_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000); // Simulate loading time
DataLabel.Text = "Data loaded successfully!";
}
When LoadButton is clicked, "Loading..." appears until the data is loaded, giving the user
visual feedback.

3. Implementing Timed Refreshes


Sometimes you want content to refresh automatically at regular intervals. You can achieve this
in ASP.NET using JavaScript with AJAX to trigger updates without user input.
Example: Timed Refresh using JavaScript with UpdatePanel
1. Use JavaScript to initiate a periodic partial postback.
2. Place the auto-refreshing content inside an UpdatePanel.
<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="AutoRefreshLabel" runat="server" Text="Content will refresh every 5
seconds." />
</ContentTemplate>
</asp:UpdatePanel>

<script type="text/javascript">
setInterval(function () {
__doPostBack('<%= UpdatePanel1.ClientID %>', '');
}, 5000); // Refresh every 5 seconds
</script>
In the code-behind, update AutoRefreshLabel on each postback:
protected void Page_Load(object sender, EventArgs e)
{
AutoRefreshLabel.Text = "Last updated: " + DateTime.Now.ToString("HH:mm:ss");
}
This script triggers a postback every 5 seconds, refreshing the content within UpdatePanel1.

4. Working with the ASP.NET AJAX Control Toolkit


The ASP.NET AJAX Control Toolkit is a set of controls that enhance the functionality of
standard web controls, adding rich features like animations, auto-complete, and pop-ups. It is
available as a NuGet package and provides several controls designed for easy integration with
AJAX.
Setting up the AJAX Control Toolkit
1. Install the Toolkit: Use NuGet Package Manager in Visual Studio to install the
AjaxControlToolkit package.
mathematica
Copy code
Install-Package AjaxControlToolkit
2. Add the Toolkit Reference: After installation, add the ToolkitScriptManager to your
page, which is a specialized version of ScriptManager.

ADVANCED WEB DEVELOPMENT


Example: Using a Control Toolkit Component (Calendar Extender)
To use a CalendarExtender for a date input:
1. Include the ToolkitScriptManager.
2. Apply the CalendarExtender control to a text box.
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ToolkitScriptManager1" />
<asp:TextBox ID="DateTextBox" runat="server" />
<ajaxToolkit:CalendarExtender TargetControlID="DateTextBox" runat="server" />
Now, clicking on DateTextBox will display a calendar popup to select a date, enhancing the
form’s interactivity.
Popular Controls in the AJAX Control Toolkit
 AutoCompleteExtender: Provides auto-complete suggestions for text inputs.
 ModalPopupExtender: Enables modal pop-ups without full-page reloads.
 Accordion: Creates collapsible panels within a page.
 SliderExtender: Adds a slider to select numeric values.
 TabContainer: Organizes content in tabbed panels.

ADVANCED WEB DEVELOPMENT

You might also like