EXP 9 AND 10 ASP,ASP NET 2.0
EXP 9 AND 10 ASP,ASP NET 2.0
NET
DATE:
AIM:
Program to demonstrate the web application in ASP using ADO.
ALGORITHM:
Step 1: Start the process.
Step 2: Create a ASP.NET Web Application.
Step 3: In the program add -> new item -> web form.
Step 4: Create a grid view for the code.
Step 5: Create database and Tables.
Step 6: Create a new SQL database in SQL Server.
Step 7: Create one or more tables in SQL Server.
Step 8: Create one or more tables in the database to store data.
Step 9: Add a Connection string to your web.config file to connect to the database.
Step 10: The data will be displayed in the web form. Stop the process.
PROGRAM:
Webform.aspx.cs
using System;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Insert data into the customers table
protected void btnInsert_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("Data Source=DHYANI_PARI;Initial
Catalog=Students;Integrated Security=True;"))
{
SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[customers] ([name],
[ph_no], [address]) VALUES (@Name, @Phone, @Address)", con);
// Add parameters to avoid SQL Injection
cmd.Parameters.AddWithValue("@Name", txtname.Text.Trim());
cmd.Parameters.AddWithValue("@Phone", txtphone.Text.Trim());
cmd.Parameters.AddWithValue("@Address", txtadd.Text.Trim());
try
{
con.Open();
int rowsAffected = cmd.ExecuteNonQuery();
if (rowsAffected > 0)
{
Response.Write("Data inserted successfully");
}
else
{
Response.Write("Insertion failed");
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
finally
{
con.Close();
}
RESULT:
Thus the above program called web application ado.net in asp has been executed successfully.
EX.NO: 10 CREATING A CUSTOM DATA-BOUND ASP.NET WEB
DATE: CONTROL FOR ASP.NET 2.0
AIM:
A program to demonstrate ASP.NET with web controls.
ALGORITHM:
Step 1 : Start the program
Step 2 : open the ASP.NET web application.
Step 3 : Right click on solution Explorer -> add new item -> web form server control & click Add.
Step 4 : Write the logic for customized controls in that and build it.
Step 5 : Create a new empty ASP.NET web application -> Solution explorer -> right click -> add new
item -> web forms and click add.
Step 6 : In toolbox, create a custom specification and choose the items of the previous web
application .dll.
Step 7 : Drag and drop the control in the web form.
Step 8 : Run the web form and perform the task.
Step 9 : Stop the process.
PROGRAM:
Webform1.aspx.cs:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : Page // Ensure it inherits from System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
[ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : CompositeControl
{
Label uname;
Label pswd; // Corrected variable name
Label label1;
TextBox textbox1;
TextBox textbox2;
Button button1;
LiteralControl lit;
protected override void CreateChildControls()
{
uname = new Label();
uname.Text = "Enter Username:";
uname.Width = Unit.Pixel(150);
pswd.RenderControl(writer);
textbox2.RenderControl(writer);
lit.RenderControl(writer);
button1.RenderControl(writer);
lit.RenderControl(writer);
label1.RenderControl(writer);
lit.RenderControl(writer);
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if (textbox1.Text == "Karthikeyan" && textbox2.Text == "23mcr019")
{
label1.Text = "Welcome";
label1.ForeColor = System.Drawing.Color.Blue;
}
else
{
label1.Text = "Wrong username or password";
label1.ForeColor = System.Drawing.Color.Red;
}
}
}
}
Webform.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication1.WebForm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebApplication1" Assembly="WebApplication1" %>
<!-- Register the custom control -->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Web Controls</title>
<style type="text/css">
.autostyle1 {
height: 29px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Web Controls</h2>
<cc1:WebCustomControl1 ID="CustomControl" runat="server" /> <!-- Updated with correct
tag prefix -->
</div>
</form>
</body>
</html>
OUTPUT:
saran
SRI
SRI
SRI
COE (30)
RECORD (20)
VIVA (10)
TOTAL (60)
RESULT:
Thus the above program demonstrate ASP.NET with controls has been executed successfully.