0% found this document useful (0 votes)
12 views13 pages

Programs 1-7

Vishal basics

Uploaded by

Leslie Qwer
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)
12 views13 pages

Programs 1-7

Vishal basics

Uploaded by

Leslie Qwer
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/ 13

PRACTICAL NO.

1
AIM: Create an application that allows the user to enter a number in the textbox named
„getnum‟. Check whether the number in the textbox „getnum‟ is palindrome or not. Print the
message accordingly in the label control named lbldisplay when the user clicks on the button
„check‟.

CODE:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PalindromeCheck
{
public partial class PalindromeNumberCheck : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btncheck_Click(object sender, EventArgs e)
{
int num = int.Parse(getNum.Text);
int n, rev = 0, d;
n = num;
while (n > 0)
{
d = n % 10;
n = n / 10;
rev = rev * 10 + d;
}
if (rev == num)
lblnum2.Text = lblnum2.Text + num + " is a Palindrome
number."; else
lblnum2.Text = lblnum2.Text + num + " is not a Palindrome number.";
}}}
PRACTICAL NO. : 2
AIM: Create an application which will ask the user to input his name and a message, display
the two items concatenated in a label, and change the format of the label using radio buttons
and check boxes for selection , the user can make the label text bold ,underlined or italic and
change its color . include buttons to display the message in the label, clear the text boxes and
label and exit.

CODE:
using System;
namespace DisplayMessage
{
public partial class DisplayTheMessage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btndisplay_Click(object sender, EventArgs e)
{
if (chkbold.Checked == true)
lblDisplay.Font.Bold = true;
else
lblDisplay.Font.Bold = false;
if (chkitalic.Checked == true)
lblDisplay.Font.Italic = true;
else
lblDisplay.Font.Italic = false;
if (chkunderline.Checked == true)
lblDisplay.Font.Underline = true;
else
lblDisplay.Font.Underline = false;
if (rbred.Checked == true)
lblDisplay.ForeColor = System.Drawing.Color.Red;
else if(rbgreen.Checked == true)
lblDisplay.ForeColor = System.Drawing.Color.Green;
else if (rbpink.Checked == true)
lblDisplay.ForeColor = System.Drawing.Color.Pink;
lblDisplay.Text = "Name:" + txtName.Text + "<br/>" + "Message:" +
txtMessage.Text;
}}}
PRACTICAL NO. : 3
AIM: List of employees is available in listbox. Write an application to add selected or all
records from listbox (assume multi-line property of textbox is true).

CODE:
using System;
namespace list
{
public partial class listselect : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < lstEmployee.Items.Count; i++)
{
if (lstEmployee.Items[i].Selected == true) txtEmployee.Text
+= lstEmployee.Items[i].Text + "\n";
}}}}
PRACTICAL NO. : 4
AIM: “How is the book ASP.NET with c# by Vipul Prakashan?” Give the user three choice :
i)Good ii)Satisfactory iii)Bad. Provide a VOTE button. After user votes, present the result in
percentage using labels next to the choices.

CODE:
using System;
namespace feedback
{
public partial class feedbackselect : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnvote_Click(object sender, EventArgs e)
{
if (rdogood.Checked == true)
{
int goodCount;
if (ViewState["gcount"] != null)
goodCount = Convert.ToInt32(ViewState["gcount"]) + 1;
else
goodCount = 1;
ViewState["gcount"] = goodCount;
}
if (rdosatisfactory.Checked == true)
{
int satisfactoryCount;
if (ViewState["scount"] != null)
satisfactoryCount = Convert.ToInt32(ViewState["scount"]) + 1;
else
satisfactoryCount = 1;
ViewState["scount"] = satisfactoryCount;
}
if (rdobad.Checked == true)
{
int badCount;
if (ViewState["bcount"] != null)
badCount = Convert.ToInt32(ViewState["bcount"]) +
1; else
badCount = 1;
ViewState["bcount"] = badCount;
}
int totalCount;
if (ViewState["count"] != null)
totalCount = Convert.ToInt32(ViewState["count"]) +
1; else
totalCount = 1;
ViewState["count"] = totalCount;
double gper = (Convert.ToDouble(ViewState["gcount"]) /
Convert.ToDouble(ViewState["count"])) * 100.0f;
lblgood.Text = gper.ToString() + "%";
double sper = (Convert.ToDouble(ViewState["scount"])
/ Convert.ToDouble(ViewState["count"])) * 100.0f;
lblsatisfactory.Text = sper.ToString() + "%";
double bper = (Convert.ToDouble(ViewState["bcount"]) /
Convert.ToDouble(ViewState["count"])) * 100.0f;
lblbad.Text = bper.ToString()+"%";
}}}

PRACTICAL NO. : 5
AIM: Create a project that calculates the total of fat, carbohydrate and protein. Allow the
user to enter into text boxes. The grams of fat, grams of carbohydrate and grams of protein.
Each gram of fat is 9 calories and protein or carbohydrate is 4 calories. Display the total
calories of the current food item in a label. Use to other labels to display and accumulated
some of calories and the count of items entered. The form food have 3 text boxes for the user
to enter the grams for each category include label next to each text box indicating what the
user is enter.

CODE:
using System;
namespace raw
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
int curr_cal, total_cal, total_items;
protected void Bcalories_Click(object sender, EventArgs e)
{
curr_cal = (Convert.ToInt32(txtfat.Text) * 9 + Convert.ToInt32(txtcarbo.Text) * 4 +
Convert.ToInt32(txtpro.Text) * 4);
lblcfc.Text = Convert.ToString(curr_cal);
lblnof.Text = Convert.ToString(total_cal);
lbltc.Text = Convert.ToString(total_items);
}
protected void Bitems_Click(object sender, EventArgs e)
{
lblnof.Text = Convert.ToString(Convert.ToInt32(lblnof.Text) + 1);
}
protected void Btotalcalo_Click(object sender, EventArgs e)
{
lbltc.Text = Convert.ToString(Convert.ToInt32(lbltc.Text) +
Convert.ToInt32(lblcfc.Text));
}
}}
PRACTICAL NO. : 6
AIM: Set the font-Arial , font style-bond , font size-18px of different controls(ie. Label,
textbox, button) using css.
Myformat.css
.BtnStyle
{
font-family:Times New Roman;
font-size:large;
font-weight:bold;
}
.TxtStyle
{
font-family:Georgia;
font-size:larger;
font-weight:400;
background-color:Maroon;
border:2px solid goldenrod;
}
.Common
{
background-color:Aqua;
color:Red;
font-family:Courier New;
font-size:20px;
font-weight:bolder;
}
Myformatting.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="cssexample.aspx.cs" Inherits="practical4css.cssexample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Roll No.:" BorderStyle="Dotted"
BackColor="Coral"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
CssClass="TxtStyle"></asp:TextBox> <br />
<asp:Label ID="Label2" runat="server" Text="Enter Name:"
CssClass="Common"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"
CssClass="TxtStyle"></asp:TextBox> <br />
<asp:Label ID="Label3" runat="server" Text="Enter Marks:"
CssClass="Common"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" CssClass="TxtStyle"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" CssClass="BtnStyle" />
<asp:Button ID="Button2" runat="server" Text="Clear" CssClass="BtnStyle" />
</div>
</form>
</body>
</html>
PRACTICAL NO. :7
AIM: Programs using ASP.NET Server controls. Create the application that accepts name,
password ,age , email id, and user id. All the information entry is compulsory. Password
should be reconfirmed. Age should be within 21 to 30. Email id should be valid. User id
should have at least a capital letter and digit as well as length should be between 7 and 20
characters

CODE:
ValidateControlForm.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ValidationControl
{
public partial class ValidationControlForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object
source, ServerValidateEventArgs args)
{
string str = args.Value;
args.IsValid = false;
if (str.Length < 7 || str.Length > 20)
{
return;
}
bool capital = false;
foreach (char ch in str)
{
if (ch >= 'A' && ch <= 'Z')
{
capital = true;
break;
}
}
if (!capital)
return;
bool digit = false;
foreach (char ch in str)
{
if (ch >= '0' && ch <= '9')
{
digit = true;
break;
}
}
if (!digit)
return;
args.IsValid = true;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
}}

You might also like