0% found this document useful (0 votes)
44 views2 pages

HTML Controls Lab

-----------------------------------------

Uploaded by

gvnbca
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)
44 views2 pages

HTML Controls Lab

-----------------------------------------

Uploaded by

gvnbca
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/ 2

ASP.

NET Lab Record

Aim:
To implement HTML controls in an ASP.NET web application using C# code-behind.

Software Requirements:
• Windows OS
• Visual Studio / Visual Studio Code
• .NET Framework / ASP.NET

Procedure:
• Open Visual Studio and create a new ASP.NET Web Application project.
• Add a new Web Form named Default.aspx.
• Design the form using HTML controls (TextBox, Password, RadioButton, CheckBox, DropDown,
Button, Label).
• Add runat="server" to each HTML control so that it can be accessed in the code-behind.
• Write the C# code in Default.aspx.cs to handle events and process inputs.
• Build and run the application.
• Enter details in the form and click Submit to see the output.

Program:

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HtmlControlsDemo

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>HTML Controls Example</title>
</head>
<body>
<form id="form1" runat="server">
<h2>HTML Controls in ASP.NET</h2>

<!-- HTML TextBox -->


<label for="txtName">Enter Name:</label>
<input type="text" id="txtName" runat="server" /><br /><br />

<!-- HTML Password -->


<label for="txtPassword">Enter Password:</label>
<input type="password" id="txtPassword" runat="server" /><br /><br />

<!-- HTML RadioButton -->


<input type="radio" id="rdbMale" name="gender" value="Male" runat="server" /> Male
<input type="radio" id="rdbFemale" name="gender" value="Female" runat="server" /> Female<br /

<!-- HTML CheckBox -->


<input type="checkbox" id="chkAgree" runat="server" /> I Agree<br /><br />

<!-- HTML DropDown -->


<select id="ddlCountry" runat="server">
<option value="India">India</option>
<option value="USA">USA</option>
<option value="UK">UK</option>
</select><br /><br />
<!-- HTML Button -->
<input type="submit" id="btnSubmit" value="Submit" runat="server" onserverclick="btnSubmit_Se

<!-- HTML Label (to show output) -->


<span id="lblMessage" runat="server"></span>
</form>
</body>
</html>

Default.aspx.cs
using System;
using System.Web.UI.HtmlControls;

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

protected void btnSubmit_ServerClick(object sender, EventArgs e)


{
string name = txtName.Value;
string password = txtPassword.Value;
string gender = rdbMale.Checked ? "Male" : rdbFemale.Checked ? "Female" : "Not Selected";
string country = ddlCountry.Value;
string agreement = chkAgree.Checked ? "Agreed" : "Not Agreed";

lblMessage.InnerHtml = $"<b>Name:</b> {name}<br/>" +


$"<b>Password:</b> {password}<br/>" +
$"<b>Gender:</b> {gender}<br/>" +
$"<b>Country:</b> {country}<br/>" +
$"<b>Agreement:</b> {agreement}";
}
}
}

Output:
---------------------------------------------------------
HTML Controls in ASP.NET
---------------------------------------------------------

Enter Name: [____________________]

Enter Password: [*************]

Gender: (•) Male ( ) Female

[✓] I Agree

Country: [ India ▼ ]

[ Submit ]

---------------------------------------------------------
Output:
Name: John
Password: 12345
Gender: Male
Country: India
Agreement: Agreed
---------------------------------------------------------

Result:
Thus, the implementation of HTML Controls in ASP.NET using C# was successfully executed and
verified.

You might also like