Simple application which contains ADDITION, SUBTRACTION,MULTIPLICATION AND DIVISION
in asp.net:
default page for design will look like this:
in asp.net:
default page for design will look like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>My Calculator</title>
<style type="text/css">
.style1
{
height: 26px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Numner1"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtNo1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="number1RequiredFieldVAlidator" runat="server"
ControlToValidate="TxtNo1" ErrorMessage="enter valid value"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Numner2"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtNo2" runat="server"></asp:TextBox>
</td>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Result="></asp:Label>
</td>
<td class="style1">
<asp:TextBox ID="TextAns" runat="server"></asp:TextBox>
</td>
<tr>
<td>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="ADD" Width="50px"
onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="SUB" Width="50px"
onclick="Button2_Click"/>
<asp:Button ID="Button3" runat="server" Text="MUL" Width="50px"
onclick="Button3_Click" />
<asp:Button ID="Button4" runat="server" Text="DIV" Width="50px"
onclick="Button4_Click" />
<p>
</p>
</form>
</body>
</html>
Code behind page for this application is here.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
TextAns.Text = Convert.ToString(Convert.ToInt32(TxtNo1.Text) + Convert.ToInt32(TxtNo2.Text));
}
protected void Button2_Click(object sender, EventArgs e)
{
TextAns.Text = Convert.ToString(Convert.ToInt32(TxtNo1.Text) - Convert.ToInt32(TxtNo2.Text));
}
protected void Button3_Click(object sender, EventArgs e)
{
TextAns.Text = Convert.ToString(Convert.ToInt32(TxtNo1.Text) * Convert.ToInt32(TxtNo2.Text));
}
protected void Button4_Click(object sender, EventArgs e)
{
if ((Convert.ToInt32(TxtNo2.Text) == 0))
{
Response.Write("Diviser can't be Zero:");
}
else
{
TextAns.Text = Convert.ToString(Convert.ToInt32(TxtNo1.Text) / Convert.ToInt32(TxtNo2.Text));
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button5_Click(object sender, EventArgs e)
{
TxtNo2.Text = TxtNo1.Text;
}
}
This is the very simple and basic starting of asp.net.
0 comments:
Post a Comment