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

C# & ASP.NET Fundamentals Guide

The document covers fundamental concepts of C# and the .NET framework, including boxing and unboxing, namespaces, and the Common Language Runtime (CLR). It also discusses ASP.NET basics such as application structure, postback events, validation controls, and state management. Additionally, it explains ADO.NET architecture, AJAX, Bootstrap, and authentication methods in ASP.NET.

Uploaded by

srcomany
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)
5 views27 pages

C# & ASP.NET Fundamentals Guide

The document covers fundamental concepts of C# and the .NET framework, including boxing and unboxing, namespaces, and the Common Language Runtime (CLR). It also discusses ASP.NET basics such as application structure, postback events, validation controls, and state management. Additionally, it explains ADO.NET architecture, AJAX, Bootstrap, and authentication methods in ASP.NET.

Uploaded by

srcomany
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

UNIT 1 – C# & .

NET Framework Fundamentals

Q1) Explain the concept of Boxing and Unboxing with


examples.

Boxing: Conversion of a value type into an object type


stored on the heap.

int num = 25;


object obj = num; // Boxing

Unboxing: Conversion of an object type back to its value


type.

int n = (int)obj; // Unboxing

Boxing happens automatically; unboxing requires explicit


casting.

Useful for storing value types in object collections or


generic collections.
Q2) Write a short note on Namespaces in .NET and
describe the System Namespace.

Namespace: Logical grouping of classes, interfaces,


structs, and other namespaces.

Purpose: Avoids naming conflicts, organizes code,


improves readability.

System Namespace: Core namespace in .NET providing:


[Link] → Input/Output operations.
[Link] → Mathematical functions.
[Link] → String manipulation.
[Link] → Date & time operations.
Collections, Exceptions, and basic types.

Q3) List and explain the services provided by the CLR


(Common Language Runtime).

Memory Management: Automatic garbage collection for


efficient memory use.
Type Safety: Ensures correct usage of data types.

Exception Handling: Provides structured runtime error


handling.

Security: Code access security and role-based security.

Thread Management: Supports multithreading in


applications.

JIT Compilation: Converts Intermediate Language (IL) to


native code at runtime.

Q4) Explain various components of CLR with a neat


diagram.

Components of CLR:

1. Class Loader: Loads class files.

2. JIT Compiler: Converts IL to native code.


3. Garbage Collector: Frees unused memory.

4. Security Engine: Manages permissions.

5. Type Checker: Ensures type safety.

6. Exception Handling Module: Manages exceptions.

7. Thread Manager: Handles thread scheduling.


Diagram:
CLR
┌────────────────────────────┐
│ Class Loader │
│ JIT Compiler │
│ Garbage Collector │
│ Security Engine │
│ Type Checker │
│ Exception Handling │
│ Thread Manager │
└────────────────────────────┘
Q5) What are Partial Classes in C#? Explain their purpose
with an example.

Partial Classes: Allow splitting a class across multiple


files.

Purpose: Enables teamwork, modularity, easier


maintenance.

Example:
// [Link]
public partial class Employee
{
public string Name;
}

// [Link]
public partial class Employee
{
public int ID;
public void Display()
{
[Link]($"ID: {ID}, Name: {Name}");
}
}

Q6) Discuss the difference between for loop and foreach


loop with examples.

for loop: Iterates using an index, can modify elements.

int[] numbers = {1,2,3};


for(int i=0;i<[Link];i++)
[Link](numbers[i]);

foreach loop: Iterates directly over collection elements,


read-only iteration.
int[] numbers = {1,2,3};
foreach(int num in numbers)
[Link](num);

Difference:
for → Flexible, allows index-based modifications.
foreach → Simpler syntax, safer, prevents accidental
modification.

UNIT 2 – [Link] Basics & Web Controls

Q1) Explain the structure of an [Link] Application.

Web Forms: Pages with .aspx extension containing HTML,


server controls, and code-behind.

Code-Behind File: .cs file with logic for the page.

[Link]: Configuration settings (database,


authentication, session state).

App_Code Folder: Contains shared classes or business


logic.

App_Data Folder: Stores databases or XML files.

Diagram of [Link] Application Structure:


MyWebApp/
├─ [Link]
├─ [Link] (Code-Behind)
├─ [Link]
├─ App_Code/
│ └─ [Link]
├─ App_Data/
│ └─ [Link]
├─ Scripts/
└─ Styles/

Q2) What is a Postback Event? Explain how it is detected


using the IsPostBack property.

Postback: When a page sends data to the server and


reloads itself.

Purpose: To maintain server-side state of controls.

Detection using IsPostBack:


if(!IsPostBack)
{
// Code executes only on first load
}
else
{
// Code executes on postback
}

Example: Loading dropdown values only on the first page


load.

Q3) Describe Validation Controls in [Link] and their


uses.

RequiredFieldValidator: Ensures a field is not empty.

CompareValidator: Compares values between controls.

RangeValidator: Checks if value falls within a range.


RegularExpressionValidator: Validates input against a
regex pattern.

CustomValidator: Custom logic for validation.

ValidationSummary: Displays all validation errors in one


place.

Q4) Explain the concept of Layered Architecture in


[Link].

Presentation Layer: UI, web forms, controls.

Business Logic Layer (BLL): Processes data, applies rules.

Data Access Layer (DAL): Interacts with database using


[Link].

Benefits: Separation of concerns, maintainability,


scalability.
Diagram:
[Presentation Layer]


[Business Logic Layer]


[Data Access Layer]


[Database]

Q5) What is the purpose of the [Link] file? Explain its


role in web applications.
[Link]: Application-level event file.

Purpose: Handles events like Application_Start,


Session_Start, Application_End.

Roles:
Application initialization and cleanup.
Session management.
Error handling at application level.
Security and logging.

Example:
protected void Application_Start(object sender, EventArgs
e)
{
// Initialize application resources
}

Q6) Explain Menu Control and SiteMapPath Control for


site navigation.

Menu Control: Displays hierarchical navigation menu.

Populates from static items or data source.

Properties: Orientation, StaticDisplayLevels, DataSource.

SiteMapPath Control: Shows breadcrumb navigation.


Reflects user location in site hierarchy.

Helps in usability and SEO.


Diagram (Menu & SiteMapPath):

Home > Products > Electronics > Mobiles

UNIT 3 – Exception Handling & State Management

Q1) What is an Exception? Explain exception handling


mechanisms in C#.
Exception: Runtime error that interrupts program
execution.

Types:
System exceptions: Predefined by .NET (e.g.,
NullReferenceException).

Application exceptions: Custom exceptions created by


developers.
Handling Mechanisms:
1. Try-Catch: Handle exceptions gracefully.
try
{
int x = 5 / 0;
}
catch(DivideByZeroException ex)
{
[Link]("Cannot divide by zero.");
}
2. Finally: Executes code regardless of exception
occurrence.

3. Throw: Used to raise exceptions manually.

Q2) Discuss State Management in [Link] and explain


Application State with an example.

State Management: Preserves user and application data


across HTTP requests.

Types:
Client-side: Cookies, ViewState, QueryString,
HiddenField.
Server-side: Session, Application, Cache.
Application State: Shared data accessible by all users.
Application["TotalUsers"] = 100;
int users = (int)Application["TotalUsers"];

Q3) Explain the role of [Link] file in State


Management.

Centralized location for handling application and session


events.

Common Events:

Application_Start – Initialize resources.

Application_End – Cleanup resources.

Session_Start – Track user sessions.


Session_End – Release session-specific resources.

Helps maintain global variables, counters, or session


data.

Q4) Describe the relationship between Content Page and


Master Page.

Master Page: Defines consistent layout (header, footer,


menu).

Content Page: Fills placeholders defined in master page.

Benefits:
Uniform look & feel.
Easy maintenance and updates.

Diagram:
[Master Page]
├─ Header
├─ ContentPlaceHolder
└─ Footer
[Content Page] → Injects content into ContentPlaceHolder

Q5) What is a Theme? Explain advantages of using themes


in a website.

Theme: Collection of CSS, skins, images defining site


appearance.

Advantages:
Consistent look across pages.
Easy to switch styles dynamically.
Reduces maintenance by centralizing style.

Example: LightTheme, DarkTheme with separate CSS.

Q6) Define Cookies and explain their use in [Link]


applications.
Cookies: Small data stored on client browser to maintain
state.

Uses:
Store user preferences.
Track user login sessions.
Personalize content.

Example:
HttpCookie userCookie = new HttpCookie("UserName");
[Link] = "JohnDoe";
[Link] = [Link](7);
[Link](userCookie);

UNIT 4 – Database Connectivity & [Link]

Q1) Explain the [Link] Architecture with diagram.

[Link]: Framework to access and manipulate data from


various sources.

Components:
1. Data Providers: Connect to specific databases (SQL
Server, Oracle).
2. Connection Object: Opens a connection to the
database.

3. Command Object: Executes SQL queries or stored


procedures.

4. DataReader: Forward-only, read-only access.

5. DataSet: In-memory, disconnected data storage.

6. DataAdapter: Bridges DataSet and database.

Diagram:
[Application]
|
[DataSet] <--> [DataAdapter] <--> [Database]
|
[DataReader] --> [Database]

Q2) What is a SqlConnection class? Explain its purpose


with example.
SqlConnection: Establishes a connection to SQL Server
database.

Properties: ConnectionString, State.

Methods: Open(), Close().

Example:
using(SqlConnection conn = new SqlConnection("Data
Source=.;Initial Catalog=DB;Integrated Security=True"))
{
[Link]();
[Link]("Connection Opened");
}

Q3) Explain Data Binding and differentiate between Single-


Value and Repeated-Value binding.

Data Binding: Linking UI controls to data sources for


display and manipulation.
Single-Value Binding: Binds a single data value to a control
(e.g., TextBox).

Repeated-Value Binding: Binds multiple data items to a


control (e.g., GridView, ListView).

Q4) Describe the GridView Control and explain how


sorting and paging are implemented.

GridView: Displays tabular data from data sources.

Sorting: Enable AllowSorting="true" and handle Sorting


event to sort data.

Paging: Enable AllowPaging="true" and handle


PageIndexChanging event for page navigation.

Example:
<asp:GridView ID="GridView1" runat="server"
AllowSorting="true" AllowPaging="true"></asp:GridView>
Q5) What is a Command Object in [Link]? Explain its
properties and methods.

Purpose: Executes SQL queries or stored procedures.

Properties: CommandText, CommandType, Connection.

Methods:
ExecuteNonQuery() → For INSERT, UPDATE, DELETE.
ExecuteScalar() → Returns single value.
ExecuteReader() → Returns DataReader object.

Example:
SqlCommand cmd = new SqlCommand("SELECT * FROM
Employee", conn);
SqlDataReader reader = [Link]();

Q6) Explain the difference between DataSet and


DataReader.
Feature DataSet DataReader
Connection Disconnected Connected
Access Read/Write Forward-only, read-only
Storage In-memory tables None (streaming)
Usage Complex operations, multiple tables Fast,
lightweight retrieval
Updates Can be updated and synced later Cannot
update

UNIT 5 – AJAX, Bootstrap & Security

Q1) Define AJAX and explain its working, advantages, and


disadvantages.

AJAX (Asynchronous JavaScript and XML): Enables


asynchronous web page updates without full page reload.

Working:
1. JavaScript sends request to server using
XMLHttpRequest.

2. Server processes request and sends response (XML,


JSON, HTML).
3. JavaScript updates part of the page dynamically.

Advantages: Faster response, reduced server load, better


user experience.
Disadvantages: SEO issues, browser compatibility,
debugging can be tricky.

Q2) What is the purpose of the UpdateProgress control in


AJAX?
Displays progress indicator during asynchronous
postback.
Properties: AssociatedUpdatePanelID, DynamicLayout,
DisplayAfter.

Usage: Helps users know the operation is in progress.


<asp:UpdateProgress ID="UpdateProgress1"
runat="server">
<ProgressTemplate>Loading...</ProgressTemplate>
</asp:UpdateProgress>

Q3) Explain the use of ScriptManager and UpdatePanel


with a demonstration.
ScriptManager: Enables AJAX for [Link] web pages.
Handles partial page updates.
UpdatePanel: Wraps controls to enable partial postbacks.

Example:
<asp:ScriptManager ID="ScriptManager1" runat="server"
/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server"
Text="Time"></asp:Label>
<asp:Button ID="Button1" runat="server"
Text="Refresh" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>

Q4) What is NuGet? Explain its role in managing [Link]


libraries.
NuGet: Package manager for .NET framework.

Role:
1. Download and install libraries easily.
2. Manage versioning and dependencies.
3. Updates libraries automatically.

Q5) Define Bootstrap and list its key features.


Bootstrap: Open-source CSS framework for responsive
web design.

Features:
1. Grid system for responsive layouts.
2. Prebuilt components: Buttons, Modals, Navbars
3. Utility classes for spacing, typography, and colors.
4. Cross-browser compatibility
5. CDN support for easy integration.

Q6) Explain Authentication in [Link] and differentiate


between Windows and Forms Authentication.

Authentication: Process to verify user identity before


granting access.

Forms Authentication: Users provide credentials through


web forms. Customizable login pages.
Windows Authentication: Uses Windows credentials of
logged-in user. Integrated with Active Directory.
| Feature | Forms Authentication | Windows
Authentication | |------------------|---------------------------
--------|--------------------------------| | Login Page | Custom
web form | OS login credentials | | Users
| Stored in database or config file | Windows domain users
| | Best For | Internet applications | Intranet
applications |

You might also like