Lab File
Lab File
Lab File
ASP.NET
(UCS4502SE)
Source Code-
using System;
class Program
}
}
Output-
Lab 2-
Program to display the first 10 natural numbers and their sum using console application
Source Code-
using System;
class Program
{
static void Main()
{
int sum = 0;
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("Natural Number " + i + " : " + i);
sum += i;
}
Console.WriteLine("Sum of the first 10 natural numbers: " + sum);
}
}
Output-
Lab 3-
Program to display the addition using the windows application.
Source Code-
using System;
using System.Windows.Forms;
namespace AdditionWindowsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Source Code-
using System;
class Program
{
static void Main()
{
Console.Write("Enter a string: ");
string input = Console.ReadLine();
Source Code-
private void button_Number_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
textBox1.Text = textBox1.Text + button.Text;
}
private void button_Clear_Click(object sender, EventArgs e)
{
textBox1.Clear();
}
private void button_Addition_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
operation = 1;
}
switch (operation)
{
case 1:
textBox1.Text = (num1 + num2).ToString();
break;
case 2:
textBox1.Text = (num1 - num2).ToString();
break;
case 3:
textBox1.Text = (num1 * num2).ToString();
break;
case 4:
textBox1.Text = (num1 / num2).ToString();
break;
}
}
float num1, num2, operation;
Output-
Lab 6-
Write a program working with Page using ASP.Net.
Source Code-
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
namespace MyApp.Pages
{
public class IndexModel : PageModel
{
public DateTime CurrentDateTime { get; set; }
Source Code-
using System.ComponentModel.DataAnnotations;
namespace SimpleFormApp.Models
{
public class ContactModel
{
[Required(ErrorMessage = "Please enter your name.")]
[StringLength(50, ErrorMessage = "Name cannot be longer than 50 characters.")]
public string Name { get; set; }
Source Code-
using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = @"Data Source=WIN-50GP30FGO75;Initial
Catalog=Demodb;User ID=sa;Password=demol23";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("Connection open!");
connection.Close();
}
}
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string query = "SELECT * FROM TableName WHERE ColumnName = @param";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add(new SqlParameter("param", value));
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}\t|{1}\t|{2}", reader[0], reader[1], reader[2]));
}
reader.Close();
connection.Close();
}
Output-
Lab 9-
Write a program to access data source through ADO.NET
Source Code-
using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = @"Data Source=WIN-50GP30FGO75;Initial
Catalog=Demodb;User ID=sa;Password=demol23";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("Connection open!");
string query = "SELECT * FROM TableName";
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}\t|{1}\t|{2}", reader[0], reader[1],
reader[2]));
}
reader.Close();
connection.Close();
}
}
}
Output-
Lab 10-
Write a program to display the following feedback form.
Source Code-
@page
@model FeedbackModel
@{
ViewData["Title"] = "Feedback";
}
<h1>Feedback Form</h1>
<form method="post">
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name"></span>
</div>
<div class="form-group">
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email"></span>
</div>
<div class="form-group">
<label asp-for="Message"></label>
<textarea asp-for="Message" class="form-control"></textarea>
<span asp-validation-for="Message"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace FeedbackApp.Pages
{
public class FeedbackModel : PageModel
{
[Required]
[StringLength(50)]
public string Name { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[StringLength(200)]
public string Message { get; set; }