Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Internals 2

The document explains the concepts of boxing and unboxing in C#, along with examples demonstrating their functionality. It differentiates between value types (like structs) and reference types (like classes), providing code examples for each. Additionally, it covers delegates, interfaces for multiple inheritance, namespaces, method parameter modifiers, and access modifiers, with relevant code snippets illustrating these concepts.

Uploaded by

Sangeetha
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)
17 views27 pages

Internals 2

The document explains the concepts of boxing and unboxing in C#, along with examples demonstrating their functionality. It differentiates between value types (like structs) and reference types (like classes), providing code examples for each. Additionally, it covers delegates, interfaces for multiple inheritance, namespaces, method parameter modifiers, and access modifiers, with relevant code snippets illustrating these concepts.

Uploaded by

Sangeetha
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/ 27

1.

Define Boxing and Unboxing with Example Programs


Boxing
Boxing is the process of converting a value type (like int, float, char) into an object type.
 The value type is stored in the stack, but when boxed, it moves to the heap.

✅ Example of Boxing:
using System;
class Program
{
static void Main()
{
int num = 10; // Value type (stored in stack)
object obj = num; // Boxing (converted to object type, moved to heap)

Console.WriteLine("Value Type: " + num);


Console.WriteLine("Boxed Object: " + obj);
}
}
Output
Value Type: 10
Boxed Object: 10
Unboxing
Unboxing is the process of converting an object type back to a value type.
 It retrieves the value from the heap and stores it back in the stack.

✅ Example of Unboxing:
using System;
class Program
{
static void Main()
{
object obj = 20; // Boxing (object type)

1
int num = (int)obj; // Unboxing (back to int)

Console.WriteLine("Boxed Object: " + obj);


Console.WriteLine("Unboxed Value: " + num);
}
}
Output
Boxed Object: 20
Unboxed Value: 20

2. Differentiate value type and reference type with c# program (structure and class)
Key Differences
Aspect Value Type (e.g., struct) Reference Type (e.g., class)
Memory Stored on the stack Stored on the heap
Allocation
Assignment Copies the actual data Copies the reference (address) to the
data
Method Passing Passed
data)
by value (copy of the Passed by reference (copies the
reference)
Default Value 0bool for numeric types, false for null for reference types

Examples int, double, struct class, string, array

a. Program for Value Type (Using struct)


A struct is a value type. When you assign a struct to another struct, the data is copied, and
the two structs are independent.
using System;

public struct MyStruct // Value type: struct


{
public int x;
public int y;

2
}

class Program
{
static void Main(string[] args)
{
// Create a struct and assign values to its fields
MyStruct struct1 = new MyStruct();
struct1.x = 10;
struct1.y = 20;

// Assign struct1 to struct2 (copying data, because struct is a value type)


MyStruct struct2 = struct1;

// Modify struct2
struct2.x = 100; // Changing struct2 does not affect struct1

// Display the values of struct1 and struct2


Console.WriteLine("Value Type - struct1: x = " + struct1.x + ", y = " + struct1.y); // x = 10,
y = 20
Console.WriteLine("Value Type - struct2: x = " + struct2.x + ", y = " + struct2.y); // x =
100, y = 20
}
}
Output:
Value Type - struct1: x = 10, y = 20
Value Type - struct2: x = 100, y = 20
Explanation:
 MyStruct is a value type. When you assign struct1 to struct2, a copy of struct1 is
created. The changes made to struct2 do not affect struct1.
b. Program for Reference Type (Using class)
A class is a reference type. When you assign one class object to another, both variables
3
refer to the same object in memory.
using System;

public class MyClass // Reference type: class


{
public int x;
public int y;
}

class Program
{
static void Main(string[] args)
{
// Create a class object and assign values to its fields
MyClass class1 = new MyClass();
class1.x = 30;
class1.y = 40;

// Assign class1 to class2 (reference type: both point to the same object)
MyClass class2 = class1;

// Modify class2
class2.x = 300; // Changing class2 will also affect class1, as they point to the same
object

// Display the values of class1 and class2


Console.WriteLine("Reference Type - class1: x = " + class1.x + ", y = " + class1.y); // x =
300, y = 40
Console.WriteLine("Reference Type - class2: x = " + class2.x + ", y = " + class2.y); // x =
300, y = 40
}
}
4
Output:
Reference Type - class1: x = 300, y = 40
Reference Type - class2: x = 300, y = 40
Explanation:
 MyClass is a reference type. When you assign class1 to class2, both variables refer
to the same object in memory. Any change made to class2 will also affect class1,
since they point to the same object.
Key Differences Recap:
 Value Type (struct): The data is copied when assigned to another variable.
Changes to one instance do not affect the other.
 Reference Type (class): The reference (memory address) is copied when assigned
to another variable. Changes to one reference affect the other because they point
to the same memory location.

3. Define delegate and its types(single and multicast) explain it in detail with program for
each.
A delegate in C# is a type that represents references to methods with a particular
parameter list and return type. A delegate allows you to call methods indirectly, through
the delegate instance, enabling a form of callback or event-handling mechanism.
In simple terms, a delegate is like a function pointer in C or C++, but it is type-safe, object-
oriented, and secure in C#.
Types of Delegates:
1. Single-cast Delegate: A delegate that holds the reference to a single method.
2. Multicast Delegate: A delegate that holds references to multiple methods. When
invoked, it calls each method in the delegate’s invocation list.
1. Single-cast Delegate:
A single-cast delegate refers to a delegate that points to a single method. It can hold only
one method reference at a time. When the delegate is invoked, only the method
referenced by the delegate is executed.
Example of a Single-cast Delegate:
using System;

public delegate void SimpleDelegate(string message);

5
class Program
{
static void Main(string[] args)
{
// Creating an instance of the delegate and assigning it to a method
SimpleDelegate del = new SimpleDelegate(ShowMessage);

// Invoking the delegate


del("Hello, this is a single-cast delegate!");

// You can also directly invoke without creating a delegate instance:


SimpleDelegate del2 = ShowMessage;
del2("Direct invocation with a delegate instance");
}

static void ShowMessage(string message)


{
Console.WriteLine(message);
}
}
Output:
Hello, this is a single-cast delegate!
Direct invocation with a delegate instance
Explanation:
 We define a delegate SimpleDelegate that takes a string as a parameter and
returns void.
 The delegate is assigned to the method ShowMessage. When del("Hello") is called,
it invokes the ShowMessage method.
 This is a single-cast delegate because it can hold only one method reference at a
time.
2. Multicast Delegate:
A multicast delegate is a delegate that can hold references to multiple methods. When
6
invoked, it calls all methods in the delegate's invocation list in the order they were added.
To create a multicast delegate, the delegate type must be able to return void because it
doesn't expect a return value from multiple methods. You can add multiple methods to
the invocation list using the += operator and remove methods using -=.
Example of a Multicast Delegate:
using System;

public delegate void MultiCastDelegate(string message);

class Program
{
static void Main(string[] args)
{
// Creating an instance of the delegate and adding methods to it
MultiCastDelegate del = new MultiCastDelegate(ShowMessage);
del += ShowGreeting;

// Invoking the multicast delegate (calls both methods)


del("Hello, this is a multicast delegate!");

// Removing one method from the multicast delegate and invoking again
del -= ShowGreeting;
Console.WriteLine("\nAfter removing ShowGreeting:");
del("Hello, only one method will be called now.");
}

static void ShowMessage(string message)


{
Console.WriteLine("Message: " + message);
}

static void ShowGreeting(string message)


7
{
Console.WriteLine("Greeting: " + message);
}
}
Output:
Message: Hello, this is a multicast delegate!
Greeting: Hello, this is a multicast delegate!

After removing ShowGreeting:


Message: Hello, only one method will be called now.
Explanation:
 The MultiCastDelegate is a delegate that can reference multiple methods
(ShowMessage and ShowGreeting).
 The delegate del is initially set to ShowMessage. Using the += operator, we add
ShowGreeting to the invocation list.
 When del("Hello") is called, it invokes both ShowMessage and ShowGreeting in the
order they were added.
 We remove ShowGreeting using the -= operator, so only ShowMessage is called
when invoking the delegate after removal.

4. Discuss the need of interface write a program on multiple inheritance using interface.
Why Do We Need Interfaces in C#?
An interface in C# is like a promise that a class will provide certain methods or actions, but
the interface itself doesn't tell you how to do them. The class that uses the interface must
define how those actions work.
1. Loose Coupling (Flexibility):
o Interfaces help keep things separate, making it easier to change your code
without affecting everything else.
2. Polymorphism (Using Different Classes the Same Way):
o Different classes can do different things, but if they use the same interface,
you can treat them the same way.
3. Multiple Inheritance (With Interfaces):
o A class can use multiple interfaces, so it can have behaviors from different
sources, even though C# doesn't allow multiple class inheritance.
8
4. Reusing Common Behaviors:
o Interfaces let different classes share the same actions, even if they aren't
related.

Program for Multiple Inheritance Using Interfaces:


In C#, multiple inheritance is achieved through interfaces, where a class can implement
multiple interfaces. Below is an example to demonstrate multiple inheritance through
interfaces.
Example:
using System;

// Defining the first interface


public interface IShape
{
void Draw();
}

// Defining the second interface


public interface IColorable
{
void FillColor(string color);
}

// Class implementing both interfaces


public class Rectangle : IShape, IColorable
{
public void Draw()
{
Console.WriteLine("Drawing Rectangle...");
}

public void FillColor(string color)


9
{
Console.WriteLine($"Filling Rectangle with color {color}.");
}
}

public class Circle : IShape, IColorable


{
public void Draw()
{
Console.WriteLine("Drawing Circle...");
}

public void FillColor(string color)


{
Console.WriteLine($"Filling Circle with color {color}.");
}
}

class Program
{
static void Main(string[] args)
{
// Create objects of Rectangle and Circle
IShape rectangleShape = new Rectangle();
IColorable rectangleColor = new Rectangle();

IShape circleShape = new Circle();


IColorable circleColor = new Circle();

// Rectangle: Using both interfaces


rectangleShape.Draw();
10
rectangleColor.FillColor("Red");

Console.WriteLine(); // Line break for clarity

// Circle: Using both interfaces


circleShape.Draw();
circleColor.FillColor("Blue");
}
}
Output:
Drawing Rectangle...
Filling Rectangle with color Red.

Drawing Circle...
Filling Circle with color Blue.
5. Define name space explain method parameter modifier with a program.
What is a Namespace in C#?
A namespace in C# is a way to organize and group related classes, interfaces, structs,
and other types. It helps to avoid naming conflicts by providing a container for types.
Using namespaces allows you to create a logical structure for your code and makes it
easier to maintain.
For example:
 The System namespace contains fundamental classes like Console, String, Int32,
etc.
 A namespace can be used to group related functionalities like classes that deal
with networking or file handling.
Method Parameter Modifiers in C#:
In C#, method parameters can be modified using none, ref, or out. These modifiers
change how parameters are passed to methods:
 None (Default): Parameters are passed by value (no changes to the original data).

 ref: Parameters are passed by reference, allowing changes inside the method to
affect the original value.
 out: Similar to ref, but used for situations where the method needs to return a

11
value through the parameter. The parameter does not need to be initialized before
being passed.

C# Program with Method Parameter Modifiers:


using System;

class Program
{
// Method with 'none' parameter (default, passed by value)
static void Add(int num1, int num2)
{
num1 = num1 + num2;
Console.WriteLine("Inside Add method (num1 + num2 = " + num1 + ")");
}

// Method with 'ref' parameter (passed by reference)


static void AddWithRef(ref int num1, int num2)
{
num1 = num1 + num2;
Console.WriteLine("Inside AddWithRef method (num1 + num2 = " + num1 + ")");
}

// Method with 'out' parameter (passed by reference, must be assigned)


static void AddWithOut(out int result, int num1, int num2)
{
result = num1 + num2; // 'result' must be assigned before returning
Console.WriteLine("Inside AddWithOut method (result = " + result + ")");
}

static void Main(string[] args)


{

12
// Default method (None, passed by value)
int a = 5, b = 10;
Add(a, b); // 'a' and 'b' are passed by value, so no changes to them
Console.WriteLine("After Add method: a = " + a + ", b = " + b);

// Method with 'ref' (passed by reference)


int x = 5, y = 10;
AddWithRef(ref x, y); // 'x' is passed by reference, so it will change
Console.WriteLine("After AddWithRef method: x = " + x + ", y = " + y);

// Method with 'out' (passed by reference, no need to initialize before)


int z;
AddWithOut(out z, 5, 10); // 'z' doesn't need initialization before
Console.WriteLine("After AddWithOut method: z = " + z);
}
}
Output:
Inside Add method (num1 + num2 = 15)
After Add method: a = 5, b = 10
Inside AddWithRef method (num1 + num2 = 15)
After AddWithRef method: x = 15, y = 10
Inside AddWithOut method (result = 15)
After AddWithOut method: z = 15

Explanation:
1. Method with none (default):
o The Add method takes two parameters num1 and num2 by value. Any
changes made to num1 inside the method do not affect the original variable
outside the method.
o Output: a and b remain unchanged after calling the Add method.
2. Method with ref:
o The AddWithRef method takes num1 by reference using the ref keyword.
13
This means changes made to num1 inside the method will reflect in the
calling method.
o Output: x changes because it was passed by reference using ref.
3. Method with out:
o The AddWithOut method takes result using the out keyword. It doesn't
need to be initialized before being passed to the method, but it must be
assigned a value inside the method before it exits.
o Output: z is assigned inside the method and shows the result.

6. Define access modifier write a program to demonstrate static keyword.


Access Modifiers in C#:
In C#, access modifiers are keywords that define the visibility and accessibility of
classes, methods, and other members. They control where a particular class, method,
or property can be accessed from.
Here are the names of the commonly used access modifiers in C#:
1. public
2. private
3. protected
4. internal
5. protected internal
6. private protected

The static Keyword in C#:


The static keyword in C# is used to define members (variables, methods, properties)
that belong to the type itself rather than to instances of the type. A static member is
shared among all instances of the class.
Here’s how static works:
 Static Methods: Can be called without creating an instance of the class. They
belong to the class rather than any specific object.
 Static Variables: Are shared across all instances of the class.

Program to Demonstrate static Keyword:


using System;

14
class Counter
{
// Static variable shared by all instances of the class
public static int count = 0;

// Static method to increment the count


public static void IncrementCount()
{
count++;
Console.WriteLine("Count incremented to: " + count);
}

// Non-static method to show the current count


public void ShowCount()
{
Console.WriteLine("Current count: " + count);
}
}

class Program
{
static void Main(string[] args)
{
// Calling the static method without creating an instance of the class
Counter.IncrementCount();
Counter.IncrementCount();
Counter.IncrementCount();

// Creating instances of the Counter class


Counter counter1 = new Counter();
Counter counter2 = new Counter();
15
// Accessing the static variable through the instances
counter1.ShowCount();
counter2.ShowCount();

// Both instances show the same static count value


}
}
Explanation:
1. Static Variable count:
o The variable count is declared static, meaning it is shared by all instances of
the Counter class.
o This variable is updated and accessed using the IncrementCount method,
which is also static.
2. Static Method IncrementCount():
o The method IncrementCount is declared static, so it can be called without
creating an instance of the Counter class. It increments the shared count
variable.
3. Non-static Method ShowCount():
o The method ShowCount() is non-static, meaning it requires an instance of
the Counter class to be called. It accesses the count variable and prints its
value.
4. Accessing Static Members:
o Static members can be accessed directly using the class name
(Counter.IncrementCount()) or through an instance (counter1.ShowCount()),
but they all refer to the same variable, count.
Output:
Count incremented to: 1
Count incremented to: 2
Count incremented to: 3
Current count: 3
Current count: 3

16
Internals 2 questions and answers

1.Discuss the steps involved in Database connection,design a form to demonstrate.


✅ Steps Involved in Database Connection in ASP.NET (Using ADO.NET with MySQL)
Connecting to a database in ASP.NET using ADO.NET involves several key steps.
Here's a breakdown of each step followed by a simple form to demonstrate the
connection.
📌 1. Include Required Namespaces
using System.Data;
using MySql.Data.MySqlClient; // For MySQL database
📌 2. Create a Connection String
A connection string provides the necessary information for the application to connect
to the database.
string connStr = "server=localhost;user
id=root;password=yourpassword;database=yourDB;";
📌 3. Open a Database Connection
Use MySqlConnection object to open a connection.
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
📌 4. Execute SQL Queries
Use MySqlCommand for executing SQL queries (SELECT, INSERT, UPDATE, DELETE).
string query = "SELECT * FROM students";
MySqlCommand cmd = new MySqlCommand(query, conn);

17
MySqlDataReader reader = cmd.ExecuteReader();
📌 5. Read and Process Data
If it’s a SELECT statement, read the data using MySqlDataReader.
while (reader.Read())
{
string name = reader["Stud_Name"].ToString();
// Process the data
}
📌 6. Close the Connection
Always close the connection after the operation.
reader.Close();
conn.Close();
🧾Example: Student Registration Form
👉 Default.aspx
<asp:TextBox ID="txtID" runat="server" Placeholder="Student ID" /><br />
<asp:TextBox ID="txtName" runat="server" Placeholder="Student Name" /><br />
<asp:TextBox ID="txtCourse" runat="server" Placeholder="Course Name" /><br />
<asp:Button ID="btnSubmit" runat="server" Text="Register" OnClick="btnSubmit_Click"
/>
<asp:Label ID="lblMessage" runat="server" ForeColor="Green" />
👉 Default.aspx.cs (Code Behind)
using System;
using MySql.Data.MySqlClient;

public partial class _Default : System.Web.UI.Page


{
string connStr = "server=localhost;user
id=root;password=yourpassword;database=studentdb;";

protected void btnSubmit_Click(object sender, EventArgs e)


18
{
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();

string query = "INSERT INTO student (Stud_ID, Stud_Name, Course_Name) VALUES


(@id, @name, @course)";
MySqlCommand cmd = new MySqlCommand(query, conn);

cmd.Parameters.AddWithValue("@id", txtID.Text);
cmd.Parameters.AddWithValue("@name", txtName.Text);
cmd.Parameters.AddWithValue("@course", txtCourse.Text);

int result = cmd.ExecuteNonQuery();

if (result > 0)
lblMessage.Text = "Student Registered Successfully!";
else
lblMessage.Text = "Failed to Register Student.";

conn.Close();
}
}
✅ Summary
Step Action
1. Include namespaces using MySql.Data.MySqlClient;
2. Define connection string Specify database, user ID, password
3. Open the connection Use MySqlConnection.Open()
4. Execute commands Use MySqlCommand for SQL operations
5. Process data (if any) Use MySqlDataReader or ExecuteNonQuery()
6. Close the connection Always close to free resources

19
2.Write a note on
a. connection oriented architecture
b. Disconnection oriented architecture
(step, clear method, properties).
Here's a clear and concise explanation for both:
a. Connection-Oriented Architecture (Connected Architecture)
In connection-oriented architecture, a continuous connection between the application
and the database is maintained for the entire data operation.
✅ Steps:
1. Open a connection using SqlConnection or MySqlConnection.
2. Execute the command using SqlCommand or MySqlCommand.
3. Use a DataReader (SqlDataReader / MySqlDataReader) to read data.
4. Close the reader and then the connection.
🧪Example:
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Students", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["Stud_Name"].ToString());
}
reader.Close();
con.Close();
📌 Properties & Methods:
 Open() – Opens the database connection.

 Close() – Closes the connection.

20
 Read() – Reads rows one-by-one (forward-only).
 IsConnected – Property to check if connection is active.

✅ Used When:
 Real-time data access is needed.

 Reading large amounts of forward-only data (like reports).

b. Disconnection-Oriented Architecture (Disconnected Architecture)


In disconnected architecture, the database connection is only open while fetching
data. The data is then stored in memory (e.g., DataSet or DataTable) and the
connection is closed.
✅ Steps:
1. Open a connection.
2. Use DataAdapter to fill a DataSet or DataTable.
3. Close the connection.
4. Work on data locally (modify, bind to UI, etc.).
🧪Example:
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Students", con);
DataSet ds = new DataSet();
da.Fill(ds, "Students"); // Fetch and store in memory
con.Close();
📌 Properties & Methods:
 Fill() – Fills the DataSet/DataTable with data.

 Update() – Pushes changes from memory back to the database.

 Tables – Property of DataSet to access data.

 Clear() – Clears the DataSet or DataTable.

✅ Used When:
 Multiple operations are needed on data without keeping the connection open.

 UI applications (like Windows Forms or ASP.NET) where data binding is needed.

21
3.Discuss relevance of validation control with appropriate example.
📌 What Are Validation Controls?
Validation controls in ASP.NET are server-side and client-side tools that automatically
check user input to ensure it meets specific rules before the form is submitted.
These controls help prevent users from submitting empty, invalid, or incorrectly
formatted data.
🎯 Why Use Validation Controls?
1. ✅ Ensures accuracy of the data (e.g., email format, number range).
2. 🔐 Prevents security risks (like SQL injection through input).
3. ⚙Reduces server errors and improves application reliability.
4. 🧑 💻 Improves user experience by showing helpful messages.
5. 💾 Protects your database from storing garbage data.
🔎 Types of Validation Controls (with Examples)
Validation Control Description Example Use
RequiredFieldValidator Ensures a textbox is not Name, Email,
empty Password
CompareValidator Compares two values Confirm password
RangeValidator Checks if input falls within a Age (18–60), Marks
range (0–100)
RegularExpressionValidator Validates format using Email, phone number
regex pattern
CustomValidator Allows writing your own Username already
validation logic taken
ValidationSummary Shows all error messages List of errors on top of
together the form
⚙ Common Properties
Property Description
ControlToValidate ID of the control to validate
ErrorMessage Message to show if validation fails

22
Property Description
Display How the message is shown (Static/Dynamic/None)
ForeColor Color of the error message
ValidationGroup Group of validations applied together
🧪Real-Life Scenario – Student Registration
Form Fields:
 Student Name (Required)

 Email (Required, must be in correct format)

 Age (Required, must be between 17 and 25)

 Confirm Email (Must match email)

💻 ASP.NET Example with Code


👇 ASP.NET Markup
<h2>Student Registration</h2>

<asp:TextBox ID="txtName" runat="server" />


<asp:RequiredFieldValidator ID="rfvName" runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required."
ForeColor="Red" /><br />

<asp:TextBox ID="txtEmail" runat="server" />


<asp:RequiredFieldValidator ID="rfvEmail" runat="server"
ControlToValidate="txtEmail"
ErrorMessage="Email is required."
ForeColor="Red" />
<asp:RegularExpressionValidator ID="revEmail" runat="server"
ControlToValidate="txtEmail"
ValidationExpression="\w+@\w+\.\w+"
ErrorMessage="Invalid email format."
ForeColor="Red" /><br />
23
<asp:TextBox ID="txtConfirmEmail" runat="server" />
<asp:CompareValidator ID="cmpEmail" runat="server"
ControlToValidate="txtConfirmEmail"
ControlToCompare="txtEmail"
ErrorMessage="Emails do not match."
ForeColor="Red" /><br />

<asp:TextBox ID="txtAge" runat="server" />


<asp:RangeValidator ID="rangeAge" runat="server"
ControlToValidate="txtAge"
MinimumValue="17" MaximumValue="25"
Type="Integer"
ErrorMessage="Age must be between 17 and 25."
ForeColor="Red" /><br />

<asp:ValidationSummary ID="ValidationSummary1" runat="server"


HeaderText="Please correct the following:"
ForeColor="Maroon" /><br />

<asp:Button ID="btnSubmit" runat="server" Text="Register" />


🧠How It Works:
 If the user leaves the name field blank, it shows: "Name is required."
 If the email format is wrong, it shows: "Invalid email format."
 If the two emails don’t match, it shows: "Emails do not match."
 If age is out of range, it shows: "Age must be between 17 and 25."
 All errors are summarized at the top by the ValidationSummary.
4.Design a form where an employee can apply for a job.
✅ Employee Job Application Form Design (ASP.NET WebForm)
You can create this using ASP.NET (Web Forms) with C#.NET for backend and
24
optionally connect to MySQL using ADO.NET.
🗂File Name: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="JobApplicationApp.Default" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Employee Job Application Form</title>
</head>
<body>
<form id="form1" runat="server">
<div style="width: 400px; margin: auto;">
<h2>Job Application Form</h2>

<label>Full Name:</label><br />


<asp:TextBox ID="txtName" runat="server" Width="100%" /><br />
<asp:RequiredFieldValidator ControlToValidate="txtName"
ErrorMessage="Name is required" ForeColor="Red" runat="server" /><br />

<label>Email:</label><br />
<asp:TextBox ID="txtEmail" runat="server" Width="100%" /><br />
<asp:RequiredFieldValidator ControlToValidate="txtEmail" ErrorMessage="Email
is required" ForeColor="Red" runat="server" />
<asp:RegularExpressionValidator ControlToValidate="txtEmail"
ValidationExpression="\w+@\w+\.\w+"
ErrorMessage="Invalid email format"
ForeColor="Red" runat="server" /><br />

<label>Qualification:</label><br />
<asp:DropDownList ID="ddlQualification" runat="server" Width="100%">

25
<asp:ListItem Text="Select" />
<asp:ListItem Text="B.E/B.Tech" />
<asp:ListItem Text="MCA" />
<asp:ListItem Text="M.Tech" />
<asp:ListItem Text="BCA" />
</asp:DropDownList><br />

<label>Experience (in years):</label><br />


<asp:TextBox ID="txtExperience" runat="server" Width="100%" /><br />
<asp:RangeValidator ControlToValidate="txtExperience" MinimumValue="0"
MaximumValue="40"
Type="Integer" ErrorMessage="Enter valid experience (0-40)" ForeColor="Red"
runat="server" /><br />

<label>Job Role Applied:</label><br />


<asp:TextBox ID="txtJobRole" runat="server" Width="100%" /><br />

<label>Upload Resume:</label><br />


<asp:FileUpload ID="fileResume" runat="server" /><br /><br />

<asp:Button ID="btnSubmit" runat="server" Text="Submit Application"


OnClick="btnSubmit_Click" /><br /><br />

<asp:Label ID="lblMessage" runat="server" ForeColor="Green" />


</div>
</form>
</body>
</html>
🧠Backend Code – Default.aspx.cs
using System;
using System.Web.UI;

26
namespace JobApplicationApp
{
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e) { }

protected void btnSubmit_Click(object sender, EventArgs e)


{
string name = txtName.Text;
string email = txtEmail.Text;
string qualification = ddlQualification.SelectedValue;
string experience = txtExperience.Text;
string jobRole = txtJobRole.Text;

// You can insert into database here using ADO.NET

lblMessage.Text = $"Application submitted successfully by {name} for the role of


{jobRole}.";
}
}
}

27

You might also like