You are on page 1of 21

💜

ASP.NET
What is .net architecture and its framework?

https://www.guru99.com/net-framework.html

1. Explain the concept of presentation layer.

practical 2 writeup

This is the top-most layer of the application where the user performs their activity. Let's take the
example of any application where the user needs to fill up a form. This form is nothing but the
Presentation Layer. In Windows applications Windows Forms are the Presentation Layer and in
web applications the web form belongs to the Presentation Layer. Basically the user's input
validation and rule processing is done in this layer.

The Presentation Layer contains pages like .aspx or Windows Forms where data is
presented to the user or input is taken from the user

Difference between Grid Layout & Liquid Layout.

Property Fixed Layout Liquid Layout

In Percentage or auto, for exp


Width of wrap In Pixels ( 960px, 1200px).
80%

Height in Pixels or auto. Automatic

For devices greater than their


Device Compatibility Remain Same. Do not compress
width.

Text Scrolling on various


Remain same Text scroll down
Devices

ASP.NET 1
Print Friendly Yes No

Fixed-Width Layouts

start with a specific size

allow a designer more direct control over how the page will look

preferred by designers with a print background

Benefits

build identical pages

Fixed-width elements such as images will not overpower text

Scan length will not be affected

Drawbacks

force horizontal scrolling

leave large expanses of white space

don't handle customer changes to font size

Liquid Layouts

based on percentages of the current browser window's size

They flex with the size of the window

preferred by designers who have a lot of information to get across in as little space as
possible

Benefits

expands and contracts

allow designer to display more content on larger computers

provide consistency

Drawbacks

very little precise control

can result in columns of text that are either too wide or too small

give error when a fixed width element is placed

3. Explain the use of Cascaded Style Sheets.

define styles of web pages

describes the look and formatting of a document

used with HTML

make presentable web pages

we do not need to provide styles repeatedly

external CSS files ⇒ changes in one file will reflect on the whole website

ASP.NET 2
provides detailed attributes

faster loading pages

easier maintenance of the websites

CSS is compatible with the older language versions.

multiple device compatibility

body{
background-color: lightblue;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.content-wrapper{
padding: 10px 30px;
}
p{
text-align: justify;
}
h1{
text-align: center;
}
.highlight{
font-weight: 700;
color: forestgreen;
}
h1, h2{
font-weight: 400;
}

ul li{
list-style-type: square;
margin-bottom: 10px;
margin-left: 50px;
}

4. How to create frond-end in ASP.NET ?

💡 check out youtube for this one

https://www.sitepoint.com/premium/books/front-end-development-with-asp-net-core-angular-and-
bootstrap/read/1/k36msnfm/

5. Explain the concept of using Namespace.


https://www.tutorialspoint.com/csharp/csharp_namespaces.htm

6. Write a short note on Data Type Conversion.

https://www.tutorialspoint.com/csharp/csharp_type_conversion.htm

7. Write a short note on Expressions in C#.


https://www.techotopia.com/index.php/C_Sharp_Operators_and_Expressions

8. What is Variable? Explain it with example.

Local Variables

ASP.NET 3
created when a function is called

destroyed after exiting the block

scope ⇒ within block


Instance Variables or Non – Static Variables

declared in a class but outside any method, constructor or block.

created when an object of the class is created and destroyed when the object is destroyed

may use access specifiers

Static Variables or Class Variables

Class variables

explicitly declared with the static modifier or inside a static block

one copy of a static variable per class

created at the start of program execution and destroyed automatically when execution
ends.

Constants Variables

keyword “const” used

can’t be modified after declaration

Read-Only Variables

readonly keyword

not compulsory to initialize

can also be initialized under the constructor

behavior will be similar to the behavior of non-static variables

using System;
class Geeks {

// instance variable
int a = 80;

// static variable
static int b = 40;

// Constant variables
const float max = 50;

// readonly variables
readonly int k;

// constructor
public Geeks()
{

// initializing readonly
// variable k
this.k = 90;
}

// Main Method
public static void Main()

ASP.NET 4
{

// Creating object
Geeks obj = new Geeks();

Console.WriteLine("The value of a is = " + obj.a);


Console.WriteLine("The value of b is = " + Geeks.b);
Console.WriteLine("The value of max is = " + Geeks.max);
Console.WriteLine("The value of k is = " + obj.k);
}
}

9. How to create Classes & Objects in C#? Explain with suitable example.

https://www.geeksforgeeks.org/c-sharp-class-and-object/

10. Explain the concept of Jagged Array in C#.

https://www.javatpoint.com/c-sharp-jagged-array

11. What are the different methods through which we can navigate among webpages?

Response.Redirect

It redirects to a new redirected URL where it is redirected in the browser.

It maintains the history and previous page is available with the back button.

It redirects the user to a web page hosted on the same server or a different server.

It has an additional round trip to the server that makes it a bit slower.

Server.Transfer

It transfers a current page request to another .aspx page on the same server.

It does not change the address bar.

It preserves server resources and avoids the unnecessary roundtrips to the server.

It cannot maintain the history.

There is no URL changes in the address bar in this case so the back button cannot be
used.

Server.Exceute

It is very similar to the server.execute method for navigation but it retains the control from
the source web page and returns to the original page after execution of the target page.

Cross Page posting

allows a web form to post on another web form on button click.

The PostbackUrl property of the button is set to the page where you want to do cross-page
posting.

12. Explain the concept of Event Handling in C#.

ASP.NET 5
💡 The event is an encapsulated delegate. C# and .NET both support the events with the
delegates.

1. In C#, event handler will take the two parameters as input and return the void.

2. The first parameter of the Event is also known as the source, which will publish the object.

3. The publisher will decide when we have to raise the Event, and the subscriber will determine
what response we have to give.

4. Event can contain many subscribers.

5. Generally, we used the Event for the single user action like clicking on the button.

6. If the Event includes the multiple subscribers, then synchronously event handler invoked.

Declaration of the Event

public event EventHandler CellEvent;

implementing the Event

declare event type of delegate

Invokation of the Event

if (CellEvent != null) CellEvent(this, e);

Hooking up the Event

OurEventClass.OurEvent += new ChangedEventHandler(OurEventChanged);

Detach the Event

OurEventClass.OurEvent -= new ChangedEventHandler(OurEventChanged);

Syntax of Delegates

<access modifier> delegate <return type> <delegate_name>(<parameters>)

Example of Delegates

class Program1
{
// declare delegate
public delegate void PrintWord(int value);

static void Main(string[] args)


{
// Print delegate points to PrintNum
PrintWord printDel = PrintNum;

ASP.NET 6
// or
// Print printDel = new Print(PrintNumber);

printDel(100000);
printDel(200);

// Print delegate points to PrintMoney


printDel = PrintMoney;

printDel(10000);
printDel(200);
}

public static void PrintNum(int num)


{
Console.WriteLine("Number: {0,-12:N0}",num);
}

public static void PrintMoney(int money)


{
Console.WriteLine("Money: {0:C}", money);
}
}

13. Write the suitable example to explain the concept of Exception Handling in C#.

Ways to transfer control from one part to another in a program

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.

throw − A program throws an exception when a problem shows up. This is done using a
throw keyword.

Exception Classes in C#

Sr.No. Exception Class & Description

1 System.IO.IOException Handles I/O errors.

System.IndexOutOfRangeException Handles errors


2 generated when a method refers to an array index out
of range.

System.ArrayTypeMismatchException Handles
3 errors generated when type is mismatched with the
array type.

System.NullReferenceException Handles errors


4
generated from referencing a null object.
System.DivideByZeroException Handles errors
5
generated from dividing a dividend with zero.

6 System.InvalidCastException Handles errors

ASP.NET 7
generated during typecasting.
System.OutOfMemoryException Handles errors
7
generated from insufficient free memory.

System.StackOverflowException Handles errors


8
generated from stack overflow.

Example

using System;

namespace UserDefinedException {
class TestTemperature {
static void Main(string[] args) {
Temperature temp = new Temperature();
try {
temp.showTemp();
} catch(TempIsZeroException e) {
Console.WriteLine("TempIsZeroException: {0}", e.Message);
}
Console.ReadKey();
}
}
}
public class TempIsZeroException: Exception {
public TempIsZeroException(string message): base(message) {
}
}
public class Temperature {
int temperature = 0;

public void showTemp() {

if(temperature == 0) {
throw (new TempIsZeroException("Zero Temperature found"));
} else {
Console.WriteLine("Temperature: {0}", temperature);
}
}
}

14. Write short notes on:

i) Web.Config

manage various settings that define a website.

settings ⇒ xml files ⇒ configure settings independently from your code


ASP.NET Configuration system is used to describe the properties and behaviors of various
aspects of ASP.NET applications.

benefits:

extensible and application specific information can be stored and retrieved easily

need not restart the web server when the settings are changed

You can use any standard text editor or XML parser to create and edit ASP.NET
configuration files.

Web.config file contains:

ASP.NET 8
Database connections

Caching settings

Session States

Error Handling

Security

types of Configuration files

Machine.config File

a global configuration file for all sites in a given machine

contains settings for all sites running on the machine

.config files inside individual website directories provide more granular control.

Web.config file

Each and Every ASP.NET application has its own copy of configuration settings
stored in a file called Web.config.

each subdirectory can have a Web.config file that includes settings that are specific
to the files and folders that are contained within the subdirectory.

ii) Global.asax

optional

handles higher level application events

contains a Class representing your application as a whole

At run time, this file is parsed and compiled into a dynamically generated .NET Framework
class

You can deploy this file as an assembly in the \bin directory

configured so that if a user requests the file, the request is rejected.

How to create a Global.asax file

iii) Masterpage
http://www-
db.deis.unibo.it/courses/TW/DOCS/w3schools/aspnet/aspnet_masterpages.asp.html#gsc.tab=0

15. Write steps to create Masterpage.


https://www.c-sharpcorner.com/article/how-to-create-master-page-in-asp-net/

ASP.NET 9
16. Explain the concept of User Control with execution steps.

https://www.educba.com/c-sharp-user-control/

17. What is Standard Control?

https://classroom.google.com/u/0/c/NTM4ODAzODE1ODIx/m/NTAyMDQzNjI0NDAw/details

18. Explain in detail Asp.Net Page Lifecycle.

video - https://youtu.be/y60P5yPlAcM

theory - https://www.tutorialspoint.com/asp.net/asp.net_life_cycle.htm

19. Explain the concept of Validation Control with its types.

💡 practical no 5 writeup -
https://classroom.google.com/u/0/c/NTM4ODAzODE1ODIx/m/NTAyMDQzNjI0NDAw/details

20. Explain use of Session Management in Asp.Net.

💡 what is session management?

Session management is a way in ASP.net to ensure that information is passed over


from one page to the other.

The view state property of a page is used to automatically pass the information of
controls from one page to the other.

The ‘Session’ object is used to store and retrieve specific values within a web page.

https://www.guru99.com/asp-net-session-management.html#:~:text=Session management is a
way,values within a web page.

21. Explain use of View State in C# with example.

What is view state?

preserve page

store control values

hidden field ⇒ encrypted value and a key.


View State values are non-transferable. So, they cannot be accessed from different pages

Features:

Retain the control value on a page without storing them in a user profile or session state.

Store page values and control properties that you set or define on a page.

Create a custom View State Provider to store the view page information in a SQL Server
Database or another database.

ASP.NET 10
What are the Data Objects that can be stored in the View State?

String

Boolean Value

Array Object

Array List Object

Hash Table

Custom type Converters

Advantages:

easy to use

flexible

server-independent

enhanced security

Disadvantages:

performance

large amount of info ⇒ slow pages


device limitations

requires sufficiently larger memory

problems viewing page on mobile

security risk

View State values are directly visible to anyone

use a Server-based state mechanism instead

no auto-track

does not track fields and values across pages

When Should You Use View State?

Case 1

When you need to store or preserve data or control values between postbacks that are
non-default.

Case 2

When you need to store application data that is not specific to a page.

How to Enable and Disable View State?

Set the EnableViewState attribute of a single control to false to disable View State for that
control.

TextBox1.EnableViewState=false;

ASP.NET 11
To disable the View State for an entire page, set the page directive's EnableViewState to
false as seen below:

<%Page Language="C#" EnableViewState="false";

22. What is Query String?

What is Query String

it is a group of keywords that send request to the web server

pass information (parameters) from one page to another

contains HTTP requests for a specific URL

specified by the values following the “?”

How to create a Query String ?

You can create a new writeable instance of HttpValueCollection by calling


System.Web.HttpUtility.ParseQueryString(string.Empty).

How to retrieve Query String ?

The QueryString collection retrieves the values of the variables in the HTTP query string
and it is specified by the values following the ?

Query String - limitations

limited length

directly visible data ⇒ may lead to falsified information


Example of query string

http://www.codingfusion.com/Post/Query-String-Example-in-Asp-Net

23. Difference between Connected & Disconnected Architectures.

https://tutorialslink.com/Articles/Connected-and-Disconnected-architecture-in-Adonet/1679

Connected Disconnected
It is connection oriented. It is dis_connection oriented.

Datareader DataSet

Disconnected get low in speed and


Connected methods gives faster performance
performance.

connected can hold the data of single table disconnected can hold multiple tables of data

connected you need to use a read only forward only data


disconnected you cannot
reader
Data Reader can't persist the data Data Set can persist the data

It is Read only, we can't update the data. We can update data

24. Write short note on SQL Connection.

ASP.NET 12
Fundamentals

Connection parameters

Database name or Data Source

Each connection can only work with one database at a time.

Credentials

used to establish a connection to the database

ensures necessary privileges

Optional parameters

parameter for how long the connection should stay active

Selecting data from the database

C# can execute ‘SQL’ select command

Inserting data into the database

Values can be specified in C# for each row that needs to be inserted into the database.

Updating data into the database

New values can be specified in C# for each row

Deleting data from a database

Select commands to specify which rows need to be deleted can be specified in C#.

SQL Command in c#

specified by the SQL connection object

methods used:

ExecuteReader() - results of query

ExecuteNonQuery() - insert, Update, and delete

How to connect C# to Database

credentials

Username – sa

Password – demo123

Step 1)

creation of a new project in Visual Studio

Step 2)

choose the project type as a Windows Forms application

give a name for the application

provide a location

click the ‘OK’ button

Step 3)

ASP.NET 13
add a button from the toolbox

text property = Connect

Step 4)

double click the form so that an event handler is added to the code for the button click
event.

Access data with the SqlDataReader

Step 1)

construct our “select” statement to read data

execute the “select” statement against the database and fetch all the table rows
accordingly.

Step 2)

display the output to the user

close all the objects

C# Insert Into Database

C# Update Database

Deleting Records

ASP.NET 14
Connecting Controls to Data

Step 1)

Construct the basic form.

drag and drop 2 components- labels and textboxes

1st label = TutorialID

2nd label = TutorialName

name property of the first textbox as txtID

name property of the second textbox as txtName

Step 2)

add a binding Navigator to the form

go to the toolbox and drag it to the form.

Step 3)

add a binding to our database

DataBindings->Text property

Step 4)

create a connection to the demotb database

creation of the connection string to the database

add the credentials to connect to the database

confirm all the settings

click on “Next”

choose the tables to be shown on the screen

Step 5)

connect the TutorialID and TutorialName textbox to the demotb table:

1. Click on the Tutorial ID control.

ASP.NET 15
2. Go to the text property of TutorialID → click on the down arrow button →
demotbBinding Source option → Tutorial ID

3. Repeat the above steps for the Tutorial Name text box.

Step 6)

change the Binding Source property of the BindingNavigator to point to our Demotb
data source

C# DataGridView

Step 1)

Drag the DataGridView control from the toolbox to the Form in Visual Studio

Step 2)

connect our data grid to the database:

choose the grid → grid configuration options → demotbBindingSource

25. What is CRUD in Asp.Net?

https://www.geeksforgeeks.org/basic-crud-create-read-update-delete-in-asp-net-mvc-using-c-
sharp-and-entity-framework/

26. Difference between Datasets & Data Adapters.

data adapter dataset

used to execute SQL


set of DataTables or collection of DataTables
statements

populate results of queries


mainly used to fetch and hold the records for one or more tables into memory.
into dataset or data table

A DataAdapter is used to populate DataSet from records returned from an SQL


gets all rows executed at
statement and also a DataSet can be created in memory and tables and data
once
can be added to it

rows can be traversed in


both forward and backward DataSet can also be converted and saved as XML file
directions

use of the Fill function to


populate the rows into
dataset

manages the connection


internally ⇒ Disconnected
Architecture

27. Write short note on:

i) Grid View

What is ASP.NET GridView?

ASP.NET 16
GridView is a control used to display data in tables on a web page. It displays data in
both rows and columns, where each column represents a field, and each row
represents a record.

GridView helps to perform key activities like Insert, Delete, Sorting, and Paging.

Properties of GridView

Name Description

represents the border width of a Web Control Server. The specified border
BorderWidth
width of a web server is negative.

sets the Cascading Style Sheets class rendered by the Web Server Control
CssClass
on the client.

helps you navigate quickly to the Web Server Control. It allows you to
AccessKey
specify the keyboard shortcut for web server control.

represents and sets the background color of the Web Server Control. By
BackColor
default, it sets the color to be empty to show that there is no property set.

sets the border color for the Web Server Control. It is inherited from the
BorderColor
WebControl base class.

Tagets the value of HtmlTextWriterTag which corresponds to the Web Server


TagKey
Control.

is used to get the name of the control tag associated with the Web Server
TagName
Control.
A Width is a unit that represents the width of a Web Server. The width of the
Width
Web Server is a negative value.

Methods of GridView

Name Description

AddedControl used when a control is added to Control’s collection.

binds a data source that invokes a server control and child controls with an
DataBind
option to raise the DataBinding event.

enables a server control to perform a cleaning operation before the release of


Dispose
memory.

used to search the current naming container for the specific server control
FindControl
with the specified id parameter.
method called immediately after a child control is removed from the controls
RemovedControl
collection of the control object.

InitializerPage initializes the page row displayed when the paging feature is enabled.

LoadViewState loads the previously saved view state of the GridView control.

method used to pass the interface for server control hierarchy to the web
OnBubbleEvent
server control.

Control Events of GridView

Name Description

performs a task when a button is clicked in the GridView


RowCommand
control.

RowCreated modify the contents of a row when a row is created. It also

ASP.NET 17
helps to determine the index of a row.

RowDeleted check the results of a deleted operation.

RowUpdated check the results of an updated operation.

An event is used to perform tasks after the user clicks a


Sorted
hyperlink to sort a column.

used to cancel the editing operations whenever the event


RowEditing
occurs.

Sorting is used to perform the sorting functionality when a


Sorting GridView control is bound to a DataTable object by setting
the data source property.

RowDataBound row is bound to data in a GridView control.

ii) Repeater Control

https://www.c-sharpcorner.com/UploadFile/puranindia/repeater-controls-in-Asp-
Net/#:~:text=The Repeater control is used,Bind Controls are container controls.

28. Explain AJAX Architecture in detail.

https://sites.google.com/a/thiyagaraaj.com/ajax/ajax-architecture

29. What is Script Manager? Explain its use with example.

Why do we need the ScriptManager?

provides support for client-side AJAX features

registers and loads the Microsoft AJAX library to enable the AJAX features.

features

Add a JavaScript proxy class for Web Services

Registering and loading Custom Client Script.

Using Authentication, Profile and Role Services from Client Script

Partial Page rendering

ScriptManagerProxy

we can have only single instance of the ScriptManager control in our webpage.

The page may contain many usercontrols

you can use a ScriptManagerProxy control to register the custom scripts or generate a
proxy for the webservice.

<asp:ScriptManager
AllowCustomErrorsRedirect="True|False"
AsyncPostBackErrorMessage="string"
EnableViewState="True|False"
ID="string"
LoadScriptsBeforeUI="True|False"
OnAsyncPostBackError="AsyncPostBackError event handler"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"

ASP.NET 18
SupportsPartialRendering="True|False"
Visible="True|False"
>
<AuthenticationService
Path="uri"
/>
<ProfileService
LoadProperties="string"
Path="uri"
/>
<RoleService
LoadRoles="True|False"
Path="uri"
/>
<Scripts>
<asp:ScriptReference
Assembly="string"
IgnoreScriptPath="True|False"
Name="string"
NotifyScriptLoaded="True|False"
Path="string"
ResourceUICultures="string"
ScriptMode="Auto|Debug|Inherit|Release"
/>
</Scripts>
<Services>
<asp:ServiceReference
InlineScript="True|False"
Path="string"
/>
</Services>
</asp:ScriptManager>

30. Explain the concept of Update Panel.

used to refresh a part of web page

two child tags -

ContentTemplate

used to place the user controls

Triggers -

allows you to define certain triggers which will make the panel update its content.

<asp:UpdatePanel ID="updatepnl" runat="server">


<ContentTemplate>

content updated asynchronously

send request Or post data to server without submitting the whole page so that is called
asynchronous

Steps to check the availability of user name in database

1. create database and sql-server

2. Open Visual Studio-->Create New Website-->ASP.NET Web Site

3. Add new Web form in the empty web application

ASP.NET 19
4. write the code to check availability in CheckAvailability.aspx.cs file

5. debug and execute

6. enter username to check if it’s available in the database.

31. What is AJAX Control Toolkit? Explain any 5 controls.

AJAX control toolkit

a shared-source library of Web widgets

widgets = extenders ⇒ server control


An extender represents a logical behavior that can be attached to one or more control types
to extend their base capabilities

The extender targets the page control with the specified ID and adds a new behavior to it.
The behavior is further configured using a few public properties

extender doesn’t interfere with the programming interface.

an extender control is limited to injecting some JavaScript code in the body


of the host page.

AJAX extender control Description

Prevents users from typing specific characters into a TextBox control. This
FilteredTextBoxExtender
extender control attaches to a TextBox control.

Enables content to be displayed, but prevents the user from interacting with
ModalPopupExtender the rest of the page. This extender control attaches to any Web server
control that can be used to open the modal window.

Displays the strength of a password. This extender control attaches to


PasswordStrength
a TextBox control.

Applies rounded corners to existing elements. This extender control


RoundedCornersExtender
typically attaches to a Panel control.

Displays a message inside a TextBox control when the text box does not
TextBoxWatermarkExtender
contain a text value. This extender control attaches to a TextBox control.

https://www.partech.nl/nl/publicaties/2021/05/basics-of-asp-net-core-ajax-control-toolkit#

32. What is Web Services? How to create & consume web services?

How to create & consume web services?

https://www.careerride.com/view/steps-to-create-and-consume-web-service-20921.aspx

What is Web Services?

A web service is a collection of open protocols and standards used for exchanging data
between applications or systems. Software applications written in various programming
languages and running on various platforms can use web services to exchange data over
computer networks like the Internet in a manner similar to inter-process communication on
a single computer. This interoperability (e.g., between Java and Python, or Windows and
Linux applications) is due to the use of open standards.

ASP.NET 20
33. What is IIS? How to install IIS on Windows? What are the steps to configure Asp.Net
website on IIS?

What is IIS?

Internet Information Services

accepts and responds to the client's computer requests and enables them to share and
deliver information

It hosts the application, websites, and other standard services needed by users

How to install IIS on Windows?

https://www.howtogeek.com/112455/how-to-install-iis-8-on-windows-8/

steps to configure website on IIS:

https://learn.microsoft.com/en-us/iis/application-frameworks/scenario-build-an-aspnet-
website-on-iis/configure-an-asp-net-website-on-iis

ASP.NET 21

You might also like