0% found this document useful (0 votes)
15 views

WEBLABC#

The document discusses server-side scripting using ASP.NET. It provides objectives and tools used. It then details two tasks - creating a table generator that takes user input for rows and columns and populates a dynamic table, and completing a web form tutorial to collect and display employee information.

Uploaded by

mu8061148
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

WEBLABC#

The document discusses server-side scripting using ASP.NET. It provides objectives and tools used. It then details two tasks - creating a table generator that takes user input for rows and columns and populates a dynamic table, and completing a web form tutorial to collect and display employee information.

Uploaded by

mu8061148
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Web Engineering

SEL-310

Lab Journal 8

MOHAMMAD UMER
01-134202-031
BS CS 6B

Department of Computer Science


BAHRIA UNIVERSITY, ISLAMABAD
Lab # 8: Server side scripting

Objectives:
• To learn about server side scripting
a. forms
b. integration
• To be able to create website on asp.net platform

Tools Used:

Visual Studio

Submission Date:
Evaluation: Signatures of Lab Engineer:

Task # 1:

Create a ASP.NET Web Forms application. Take, as input, the number of rows and number of columns
from the user in that form. After the form is submitted to the server (posted back using “submit”), the
page should be displayed showing a table having the same number of rows and columns as were
input/submitted by the user originally. Populate each cell of the table with the sum of its row number
and column number. For example, cell in row 1 column 1 should display the value 2 as 1+1 = 2
Procedure/Program:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1._Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Table Generator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Table Generator</h2>
<asp:Label ID="lblRows" runat="server" Text="Number of Rows:"></asp:Label>
<asp:TextBox ID="txtRows" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblColumns" runat="server" Text="Number of
Columns:"></asp:Label>
<asp:TextBox ID="txtColumns" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Generate Table"
OnClick="btnSubmit_Click" />
</div>
<br />
<div id="tableContainer" runat="server">
<asp:Table ID="table" runat="server"></asp:Table>
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
GenerateTable();
}
}

protected void btnSubmit_Click(object sender, EventArgs e)


{
GenerateTable();
}

private void GenerateTable()


{
int rows, columns;
if (int.TryParse(txtRows.Text, out rows) && int.TryParse(txtColumns.Text, out
columns))
{

table.Rows.Clear();

for (int i = 0; i < rows; i++)


{
TableRow row = new TableRow();

for (int j = 0; j < columns; j++)


{
TableCell cell = new TableCell();
cell.Text = (i + 1 + j + 1).ToString();

cell.Style["border"] = "1px solid black";


cell.Style["padding"] = "5px";

row.Cells.Add(cell);
}

row.Style["border"] = "1px solid black";

table.Rows.Add(row);
}

table.Style["border"] = "1px solid black";


table.Style["border-collapse"] = "collapse";
table.Style["padding"] = "5px";

tableContainer.Visible = true;
}
}

}
}

Result/Output:

Analysis:
Task # 2:

Complete (all steps of) the ASP.NET web form explained in the class tutorial.

Procedure/Program:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Employee Information</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Employee Information</h2>
<label for="txtFirstName">First Name:</label>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<br />
<label for="txtLastName">Last Name:</label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<br />
<label for="ddlGender">Gender:</label>
<asp:DropDownList ID="ddlGender" runat="server">
<asp:ListItem Text="Male" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:DropDownList>
<br />
<label for="ddlDepartment">Department:</label>
<asp:DropDownList ID="ddlDepartment" runat="server">
<asp:ListItem Text="HR" Value="HR"></asp:ListItem>
<asp:ListItem Text="IT" Value="IT"></asp:ListItem>
<asp:ListItem Text="Finance" Value="Finance"></asp:ListItem>
<asp:ListItem Text="Marketing" Value="Marketing"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" />
<br />
<asp:Label ID="lblResult" runat="server" Visible="false"></asp:Label>
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnSubmit_Click(object sender, EventArgs e)


{
string firstName = txtFirstName.Text;
string lastName = txtLastName.Text;
string gender = ddlGender.SelectedValue;
string department = ddlDepartment.SelectedValue;

// Process the user's information as needed


// For this example, let's just display the information on the page

string message = $"First Name: {firstName}<br />" +


$"Last Name: {lastName}<br />" +
$"Gender: {gender}<br />" +
$"Department: {department}";

lblResult.Text = message;
lblResult.Visible = true; // Show the result label
}
}
}

Result/Output:
Analysis:

You might also like