0% found this document useful (0 votes)
66 views3 pages

Server 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)
66 views3 pages

Server 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/ 3

ASP.

NET Lab Record

Aim:
To implement ASP.NET Server Controls (TextBox, Label, RadioButton, CheckBox, DropDownList,
Button) 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 ServerControls.aspx.
• Design the form using ASP.NET Server Controls.
• Set runat="server" for all server controls (default in ASP controls).
• Write the C# code in ServerControls.aspx.cs to process input values and display output.
• Build and run the project.
• Enter details in the form and click Submit to view the results.

Program:

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

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

<!-- Server TextBox -->


<asp:Label ID="lblName" runat="server" Text="Enter Name:" />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br /><br />

<!-- Server Password -->


<asp:Label ID="lblPassword" runat="server" Text="Enter Password:" />
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
<br /><br />

<!-- Server RadioButtons -->


<asp:Label ID="lblGender" runat="server" Text="Select Gender:" />
<asp:RadioButton ID="rdbMale" runat="server" GroupName="Gender" Text="Male" />
<asp:RadioButton ID="rdbFemale" runat="server" GroupName="Gender" Text="Female" />
<br /><br />

<!-- Server CheckBox -->


<asp:CheckBox ID="chkAgree" runat="server" Text="I Agree" />
<br /><br />

<!-- Server DropDownList -->


<asp:Label ID="lblCountry" runat="server" Text="Select Country:" />
<asp:DropDownList ID="ddlCountry" runat="server">
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
</asp:DropDownList>
<br /><br />

<!-- Server Button -->


<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<br /><br />

<!-- Server Label for Output -->


<asp:Label ID="lblMessage" runat="server" ForeColor="Blue"></asp:Label>
</form>
</body>
</html>

ServerControls.aspx.cs
using System;

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

protected void btnSubmit_Click(object sender, EventArgs e)


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

lblMessage.Text = $"<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:
---------------------------------------------------------
ASP.NET Server Controls Example
---------------------------------------------------------

Enter Name: [John ]


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

Select Gender: (•) Male ( ) Female

[✓] I Agree

Select Country: [ India ▼ ]

[ Submit ]

---------------------------------------
Output:
Name: John
Password: 12345
Gender: Male
Country: India
Agreement: Agreed
---------------------------------------------------------
Result:
Thus, the implementation of ASP.NET Server Controls using C# was successfully executed and
verified.

You might also like