ASP.NET Question Bank and Answers
ASP.NET Question Bank and Answers
Example:
Suppose you have a User table in the database. Instead of passing your
entire entity (which may have extra info or methods), you can use a DTO:
// Transfer Object (DTO)
public class UserDTO
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
[Link] = dt;
[Link]();
}
}
3|Page
• .axd → Special handler file (e.g., [Link], [Link])
• .browser → Browser definition file
• .sitemap → Site navigation file
• .skin → Theme/skin file for controls
• .master → Master Page file
• .config → Configuration file (e.g., [Link], [Link])
• .cs / .vb → Code-behind files (C# or [Link])
• .resx → Resource file for localization/globalization
4|Page
8. Differentiate dataset and data reader.
→
Feature DataSet DataReader
Connected architecture
Disconnected architecture
Nature (needs continuous
(works offline).
connection to DB).
Can hold multiple tables at Reads data from one
Data Storage
once (in-memory cache). table/query at a time.
Allows forward and backward
Navigation Forward-only, read-only.
navigation.
Slower due to overhead Faster as it reads data
Performance
(stores more data). directly from DB.
Allows insert, update, delete
Data Only reads data, cannot
in memory and later sync
Manipulation modify.
with DB.
When working with complex
When fast, read-only,
Best Use data (multiple tables,
forward access is needed.
relations).
5|Page
Q2: Answer the following questions: (5 or 7 Marks each)
2. Start
o Page properties such as Request and Response are set.
o Determines whether the request is a postback (form submission)
or a new request.
6|Page
4. Load ViewState
o Restores control properties from the hidden __VIEWSTATE field (if
postback).
o Ensures that controls maintain values between postbacks.
7. PreRender
o Final changes to the page or controls can be made before
rendering.
o Last chance to modify content before output is generated.
8. Render
o The page and its controls generate the final HTML that will be sent
to the browser.
9. Unload
o Cleanup stage.
o Page and control objects are disposed.
o Resources such as database connections are released.
7|Page
Diagram (for clarity in exams)
Page Request → Start → Init → Load ViewState → Load → Postback Events →
PreRender → Render → Unload
8|Page
Advantages of [Link]
1. Separation of Code and Design
o Code (C# or [Link]) is placed in the code-behind file (.cs), and
design (HTML/ASPX) is separate.
o Makes development and maintenance easier.
3. State Management
o [Link] provides mechanisms like ViewState, Session,
Cookies, and Application State to maintain user data across
requests.
4. Security
o Provides built-in authentication and authorization (Forms
Authentication, Windows Authentication).
o Supports role-based security and membership providers.
6. Cross-Language Support
o Any .NET language (C#, [Link], F#) can be used for development.
9|Page
o Makes it flexible for different teams.
8. Built-in Caching
o [Link] has output caching, data caching, and fragment caching
to enhance performance by reducing database calls.
3. List types of control used to create ASP .NET page. Explain TreeView
control in detail.
→ Types of Controls in [Link]
[Link] provides several types of controls to build dynamic web pages:
1. HTML Controls
o Standard HTML elements (<input>, <button>, <table>) that can be
run on the server by adding runat="server".
o Example:
o <input type="text" id="txtName" runat="server" />
2. Web Server Controls
o Rich set of controls provided by [Link].
o Examples: TextBox, Button, DropDownList, GridView, TreeView.
10 | P a g e
o Automatically render HTML and support events.
3. Validation Controls
o Used for input validation.
o Examples: RequiredFieldValidator, RangeValidator,
CompareValidator.
4. Rich Controls / Data Controls
o Used to display and manage data.
o Examples: GridView, DataList, DetailsView.
5. Navigation Controls
o Used for site navigation.
o Examples: Menu, TreeView, SiteMapPath.
Features
• Supports hierarchical data binding (XML, SiteMap, database).
• Provides expand/collapse functionality.
• Can be used for menus, directories, categories, etc.
• Supports checkboxes for node selection.
Example
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
11 | P a g e
<asp:TreeNode Text="Home"
NavigateUrl="~/[Link]"></asp:TreeNode>
<asp:TreeNode Text="Products">
<asp:TreeNode Text="Electronics"
NavigateUrl="~/[Link]"></asp:TreeNode>
<asp:TreeNode Text="Clothing"
NavigateUrl="~/[Link]"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Contact Us"
NavigateUrl="~/[Link]"></asp:TreeNode>
</Nodes>
</asp:TreeView>
This will create a tree menu with Home, Products (expandable:
Electronics, Clothing), and Contact Us.
4. What are the advantages of themes over CSS. Explain various ways to
apply skin file.
→ Advantages of Themes over CSS in [Link]
While CSS is used to style HTML elements, [Link] Themes (with Skin
files) provide additional advantages:
12 | P a g e
1. Server-Side Integration
o Themes and Skins are [Link] aware. They can apply styles
directly to server controls (e.g., Button, TextBox), not just HTML
tags.
2. Consistency Across Application
o A theme can include CSS, Skin files, and Images in one package,
ensuring a consistent look throughout the entire application.
3. Control-Level Styling (Skins)
o Skins let you define default properties for [Link] controls (like
Font, BackColor, BorderStyle) which CSS alone cannot do.
Example skin:
<asp:Button runat="server" ForeColor="White" BackColor="Blue" Font-
Bold="true" />
4. Separation of Design and Logic
o Developers can focus on code while designers can work on
Themes separately.
5. Runtime Switching
o Themes can be changed dynamically at runtime for
personalization (e.g., Dark/Light mode).
13 | P a g e
2. [Link] Level (Global Application Theme)
<configuration>
<[Link]>
<pages theme="MyTheme" />
</[Link]>
</configuration>
Applies the theme to all pages in the application.
14 | P a g e
o Database connection is opened only to fetch data and to save
updates back.
o Saves resources and improves scalability.
3. XML Support
o DataSet can read/write XML, making it portable across
applications.
4. Data Manipulation
o Allows insert, update, delete operations locally.
o Changes are tracked using a DataAdapter and can be
synchronized with the database.
// Create DataSet
DataSet ds = new DataSet();
15 | P a g e
[Link](row["Name"]);
}
16 | P a g e
Feature DataSet DataReader
Suitable for large data Best for fast, read-only
Data Volume
manipulation and caching. operations.
Can modify data locally and
Cannot modify data (read-
Updates update DB later via
only).
DataAdapter.
XML Support Can read/write data as XML. No XML support.
Slightly slower (overhead of Faster (direct, forward-only
Performance
storing in memory). stream).
Example in C#
using System;
using [Link];
class Program
{
static void Main()
{
string conStr = "Data Source=.;Initial Catalog=SchoolDB;Integrated
Security=True";
17 | P a g e
SqlConnection con = new SqlConnection(conStr);
[Link]();
SqlDataReader reader = [Link]();
[Link]();
[Link]();
}
}
18 | P a g e
2. RangeValidator
3. CompareValidator
4. RegularExpressionValidator
5. CustomValidator
6. ValidationSummary
RangeValidator
• Ensures that input value falls within a specific range.
• Can validate numeric, date, or string ranges.
• Example:
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
19 | P a g e
<asp:RangeValidator
ID="rvAge"
runat="server"
ControlToValidate="txtAge"
MinimumValue="18"
MaximumValue="60"
Type="Integer"
ErrorMessage="Age must be between 18 and 60!"
ForeColor="Red">
</asp:RangeValidator>
<!DOCTYPE html>
<html>
<head runat="server">
<title>My Site</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Site Header</h1>
21 | P a g e
<asp:ContentPlaceHolder ID="MainContent"
runat="server"></asp:ContentPlaceHolder>
<footer>Site Footer</footer>
</div>
</form>
</body>
</html>
Example in C#
23 | P a g e
using System;
using [Link];
using [Link];
class Program
{
static void Main()
{
string conStr = "Data Source=.;Initial Catalog=SchoolDB;Integrated
Security=True";
SqlConnection con = new SqlConnection(conStr);
// Create DataSet
DataSet ds = new DataSet();
// Display data
foreach (DataRow row in [Link]["Students"].Rows)
{
[Link]("ID: " + row["StudentID"] + ", Name: " +
row["Name"]);
}
24 | P a g e
// Modify DataSet locally
[Link]["Students"].Rows[0]["Name"] = "John Updated";
// Update database
[Link](ds, "Students");
}
}
2. Calendar Control
Definition
The Calendar control in [Link] allows users to select dates easily.
• Displays a monthly calendar view.
• Can be used to pick single or multiple dates.
Features
• Supports date selection events like SelectionChanged.
• Allows formatting, multiple months display, navigation between
months and years.
• Can restrict dates using TodaysDate, SelectionMode, etc.
Example
<asp:Calendar ID="Calendar1" runat="server"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:Label ID="lblDate" runat="server" Text=""></asp:Label>
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
26 | P a g e
{
[Link] = "Selected Date: " +
[Link]();
}
QueryString in Detail
Definition
27 | P a g e
• The QueryString is a client-side state management technique that
passes data from one page to another using the URL.
• Data is appended to the URL after a ? symbol in name=value format.
Features of QueryString
1. Easy to use and requires no server memory.
2. Values are visible in the URL.
3. Can pass small amounts of data (not secure for sensitive
information).
4. Can be retrieved using [Link]["key"].
Example
[Link]
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Go"
OnClick="btnSubmit_Click" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
string name = [Link];
[Link]("[Link]?user=" + name);
}
[Link]
<asp:Label ID="lblUser" runat="server"></asp:Label>
protected void Page_Load(object sender, EventArgs e)
{
if ([Link]["user"] != null)
{
[Link] = "Welcome, " + [Link]["user"];
28 | P a g e
}
}
[WebService(Namespace = "[Link]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyService : [Link]
{
[WebMethod]
public string SayHello(string name)
{
29 | P a g e
return "Hello, " + name;
}
[WebMethod]
public int AddNumbers(int a, int b)
{
return a + b;
}
}
13. What is a User Control? Explain creating and using a user control in
[Link].
→ What is a User Control
• A User Control is a custom, reusable control in [Link] that is
created by combining existing server controls and code.
• It has the file extension .ascx.
• User controls are used to avoid code duplication and maintain
consistent UI across multiple pages.
• Example: Header, Footer, Login Panel, Navigation Menu.
Features
1. Built-in UI for username and password.
32 | P a g e
2. Supports authentication with Membership database or custom code.
3. Automatically provides failure messages on wrong login.
4. Supports PasswordRecovery, Remember Me, and redirect on
successful login.
33 | P a g e
{
[Link] = false; // Login failed
}
}
<asp:Login ID="Login1" runat="server"
OnAuthenticate="Login1_Authenticate" />
15. Consider table having following fields: Customer (c_id, name, city) Write
a code to perform insert, update and delete operation.
→ Table Structure
Customer
c_id INT PRIMARY KEY
name VARCHAR(50)
city VARCHAR(50)
[Link] Example (Using [Link] and SQL Server)
1. Connection String
string conStr = "Data Source=.;Initial Catalog=YourDatabase;Integrated
Security=True";
2. Insert Operation
using [Link];
[Link]();
[Link]();
[Link]();
}
}
3. Update Operation
void UpdateCustomer(int id, string name, string city)
{
using (SqlConnection con = new SqlConnection(conStr))
{
string query = "UPDATE Customer SET name=@Name, city=@City
WHERE c_id=@Id";
SqlCommand cmd = new SqlCommand(query, con);
[Link]("@Id", id);
[Link]("@Name", name);
[Link]("@City", city);
[Link]();
[Link]();
[Link]();
}
}
4. Delete Operation
35 | P a g e
void DeleteCustomer(int id)
{
using (SqlConnection con = new SqlConnection(conStr))
{
string query = "DELETE FROM Customer WHERE c_id=@Id";
SqlCommand cmd = new SqlCommand(query, con);
[Link]("@Id", id);
[Link]();
[Link]();
[Link]();
}
}
5. Example Usage in [Link] Page
protected void btnInsert_Click(object sender, EventArgs e)
{
InsertCustomer(1, "John", "Delhi");
}