For your final project, you are to create a two-page web application of your cho
ID: 3782076 • Letter: F
Question
For your final project, you are to create a two-page web application of your choice. ASP.NET : C#
You must include the following items:
At least 5 different standard server controls
At least 2 validation controls
At least 1 navigation control ~ one must navigate back and forth to each page One session state element
Upon completion of your two-page web application, you will provide a two page report describing the functions of the web application as well as each control that you have included in your design.
Explanation / Answer
Aspx.page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="samplePro.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
//validation
$(document).ready(function () {
$('#lnkTable').click(function () {
$('#grid').toggle();
})
$('#btnSubmit').click(function () {
var count = 0;
if ($('#txtName').val().trim() == "") {
alert("Enter the name");
return false;
}
else if ($('#txtEmail').val().trim() == "") {
alert("Enter the Email");
return false;
}
else if ($('#txtSalary').val().trim() == "") {
alert("Enter the Salary");
return false
}
});
});
</script>
</head>
<body>
<form runat="server">
<div class="container">
<asp:HyperLink ID="lnkTable" CssClass="btn-link btn pull-right" runat="server">Dispaly Table</asp:HyperLink>
<div class="row">
<div class="form-horizontal col-lg-8 col-lg-offset-2">
<div class="form-group">
<label class="control-label col-sm-4">Employee Name:</label>
<div class="col-sm-8">
<asp:TextBox ID="txtName" class="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Employee Email:</label>
<div class="col-sm-8">
<asp:TextBox ID="txtEmail" class="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Employee Gender:</label>
<div class="col-sm-8">
<asp:RadioButtonList ID="rdbGender" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Male" Selected="True" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Employee Department:</label>
<div class="col-sm-8">
<asp:DropDownList ID="ddlDept" CssClass="form-control" runat="server">
<asp:ListItem Text="IT" Value="IT"></asp:ListItem>
<asp:ListItem Text="VFX" Value="VFX"></asp:ListItem>
<asp:ListItem Text="INFOMATICA" Value="INFOMATICA"></asp:ListItem>
</asp:DropDownList>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Salary:</label>
<div class="col-sm-8">
<asp:TextBox ID="txtSalary" class="form-control" runat="server"></asp:TextBox>
</div>
</div>
<asp:Button ID="btnSubmit" CssClass="btn btn-success center-block" runat="server" Text="Submit" />
<br />
<asp:Label runat="server" ID="lblRes" CssClass="center-block"></asp:Label>
</div>
</div>
<div id="grid">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</div>
</form>
</body>
</html>
.CS .Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace samplePro
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
BindGridView();
}
protected void BindGridView()
{
SqlCommand cmd = new SqlCommand("select * from Employee", con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into Employee (EmpName, Gender,Department, Salary,Email) values('" + txtName.Text + "', '" + rdbGender.SelectedValue + "', '" + ddlDept.SelectedValue + "', '" + txtSalary.Text + "', '" + txtEmail.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblRes.Text = "Insert Successful";
clear();
}
protected void clear()
{
txtSalary.Text = "";
txtName.Text = "";
txtEmail.Text = "";
ddlDept.SelectedIndex = 0;
rdbGender.SelectedIndex = 0;
}
}
}
add connection string in Web.config page
<connectionStrings>
<add name="DBCS" connectionString="Data Source=MITTU-PCMITTU;Initial Catalog=Test;User ID=sa;Password=Deva@123" providerName="System.Data.SqlClient" />
</connectionStrings>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.