5. Practicals(Application Development using .Net Technology Framework)
5. Practicals(Application Development using .Net Technology Framework)
Allow The
User To Enter Into Text Boxes. the Grams of Fat, Grams Of Carbohydrate And Grams Of
Protein. Each Gram of Fat Is 9 Calories and Protein Or Carbohydrate Is Calories. Display the Total
Calories of The Current Food Item In A Label. Use To Other Labels To Display And Accumulated
Some Of Calories And The Count Of Items Entered. The form food have 3 text boxes For The User
To Enter The Grams For Each Category Include Label Next To Each Text Box Indicating What
The User Is Enter.
Solution:
Steps:
- Three Label controls to indicate what each TextBox is for (e.g., "Grams of Fat:", "Grams
of Protein:", "Grams of Carbohydrates:").
- Three TextBox controls for users to enter the grams of fat, protein, and carbohydrates.
- Three Label controls to display the calculated calories for fat, protein, and carbohydrates.
- Three more Label controls to display the accumulated calories for each category.
- Make sure to arrange these controls in a clear and organized manner on your form.
4. Write the C# code to calculate the total calories, update the accumulated calories, and
count of items entered. Here's a sample code for your form:
```csharp
using System;
using System.Windows.Forms;
namespace FoodCalorieCalculator
public Form1()
InitializeComponent();
itemCount++;
```
5. Set the event handler for the "Calculate Calories" button's click event. You can do this by
double-clicking the button in the form designer, which will generate the
`CalculateCaloriesButton_Click` event handler.
6. Build and run your application to test the food calorie calculator.
Practical 10. Create The Web Application That Accepts Name, Password ,Age , Email I‹:1, And
User Id. All The Information Entry Is Compulsory. Password Should Be Reconfirmed. Age
Should Be Within 21 To 30. Email Id Should Be Valid. User Id Should Have At Least A Capital Letter
And Digit As Well As Length Should Be Between 7 And 20 Characters.
Solution:
To create a web application in C# .NET that accepts user information (Name, Password, Age,
Email, and User ID) with validation rules, you can follow these steps:
1. Open Visual Studio or any other C# IDE.
- Five Label controls to indicate each input field (Name, Password, Confirm Password,
Age, Email, User ID).
- Make sure to arrange these controls in a clear and organized manner on your web form.
4. Add validation controls to enforce the validation rules for each input field. You can use
RequiredFieldValidator, RangeValidator, RegularExpressionValidator, and CustomValidator
controls for different validation tasks.
```html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Registration Form</h2>
</div>
</form>
</body>
</html>
```
5. In the code-behind (WebForm1.aspx.cs), add the event handler for the Submit button:
```csharp
using System;
using System.Web.UI;
if (Page.IsValid)
// You can perform further actions with the collected data here
else
```
6. Build and run your ASP.NET web application to test the registration form with validation.