Practical 1 (A) Working with basic C# and ASP .NET
Автор: Viju the Solution
Загружено: 2025-12-11
Просмотров: 85
Описание:
Create an ASP.NET application that takes 4 integer inputs from the user and displays the product.
🟦 STEP 1 — Create a New ASP.NET Web Application
Open Visual Studio
Click Create a new project
Select ASP.NET Web Application (.NET Framework)
Click Next
Give a name → ProductOfNumbers
Choose:
Framework: .NET Framework 4.x
Template: Empty (check Web Forms)
Click Create
This creates your project.
🟦 STEP 2 — Add a Web Form
Right-click the project → Add → Web Form
Name it: Default.aspx
Click Add
Now you have two files:
Default.aspx
Default.aspx.cs (code-behind file)
🟦 STEP 3 — Design the UI (Default.aspx)
You need:
4 TextBoxes
1 Button
1 Label to show result
Replace your Default.aspx content with:
<form id="form1" runat="server">
<div>
<h2>Enter Four Numbers</h2>
<asp:TextBox ID="txtNum1" runat="server"></asp:TextBox><br /><br />
<asp:TextBox ID="txtNum2" runat="server"></asp:TextBox><br /><br />
<asp:TextBox ID="txtNum3" runat="server"></asp:TextBox><br /><br />
<asp:TextBox ID="txtNum4" runat="server"></asp:TextBox><br /><br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate Product"
OnClick="btnCalculate_Click" />
<h3>Product: <asp:Label ID="lblResult" runat="server"></asp:Label></h3>
</div>
</form>
✔ This creates your input boxes and button.
🟦 STEP 4 — Write the C# Code (Default.aspx.cs)
Double-click the Calculate Button or add the code manually:
protected void btnCalculate_Click(object sender, EventArgs e)
{
int a = int.Parse(txtNum1.Text);
int b = int.Parse(txtNum2.Text);
int c = int.Parse(txtNum3.Text);
int d = int.Parse(txtNum4.Text);
int product = a * b * c * d;
lblResult.Text = product.ToString();
}
✔ This code runs when the button is clicked.
🟦 STEP 5 — How the Code Works (Explanation)
1. User enters numbers
User types 4 integer values in textboxes:
txtNum1
txtNum2
txtNum3
txtNum4
2. Button is clicked
btnCalculate_Click method gets executed.
3. Text from input boxes is read
int.Parse(txtNum1.Text)
Converts textbox text → integer.
4. Product is calculated
int product = a * b * c * d;
5. Output is shown
lblResult.Text = product.ToString();
Label shows result on screen.
🟦 STEP 6 — Run the Application
Press F5 or click Start
Browser will open
Enter four numbers
Click Calculate Product
You will see the result
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: