AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Area converter in .net
Posted by kalyani on  2/19/2008 7:15:37 AM Category: ADO.NET
Add to my favorites
Email to friend
I want code for Area converter in .net 2.0 please provide


i wrote client side script but it's not working. Here the code.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>Untitled Page</title>
<script language="javascript" type="text/javascript">

function fnConvert()
{

var objarea=document.getElementById("txtConvert");
if(CheckForEmpty(objarea,"Enter a numeric value to convert.",true,true)==false)
{
return false;
}

if(isNaN(objarea.value))
{

alert("Enter a numeric value to convert.")
objarea.value="";
objarea.focus();
return false;
}

if(parseInt(objarea.value)== 0)
{
alert("Please type a proper value to convert");
objarea.value="";
objarea.focus();
return false;
}
var objfrom=document.getElementById("ddlFromUnit");
if(objfrom.selectedIndex==0)
{
alert("Select an area")
objfrom.focus();
return false;
}
var objto=document.getElementById("ddlToUnit");
if(objto.selectedIndex==0)
{
alert("Select an area");
objto.focus();
return false;
}
debugger;
var dblResult=0;
if(objfrom.selectedIndex == 7 || objto.selectedIndex == 7 )
{
if(objfrom.selectedIndex == 7 && objto.selectedIndex == 7)
{
alert('hi Ammu');
document.getElementById("lblResult").innerHTML = objarea.value + " Cents = " + objarea.value + " Cents";
return;
}

var cents = new Array();
cents[0] = "0.00999853";
cents[1] = "0.18147503";
cents[2] = "0.00404634";
cents[3] = "435.540069";
cents[4] = "48.3933410";
cents[5] = "40.5052264";
var result = 0;


if(objfrom.selectedIndex == 7)

result = RoundDecimals(objarea.value * cents[objto.selectedIndex-1],3);
else if(objto.selectedIndex == 7)

result = RoundDecimals(objarea.value / cents[objfrom.selectedIndex-1],3);
document.getElementById("lblResult").innerHTML = objarea.value + " " + objfrom.options[objfrom.selectedIndex].text + " = " + result + " " +objto.options[objto.selectedIndex].text;
return;
}

if(objfrom.selectedIndex==2 && objto.selectedIndex!=2){dblResult=(objarea.value*2400) * objfrom.options[4].value/objto.options[objto.selectedIndex].value;}

else if(objto.selectedIndex==2 && objfrom.selectedIndex!=2){dblResult=(objarea.value/2400) * objfrom.options[objfrom.selectedIndex].value/objto.options[4].value;}

else{dblResult=objarea.value * objfrom.options[objfrom.selectedIndex].value/objto.options[objto.selectedIndex].value;}
document.getElementById("lblResult").innerHTML=objarea.value+" " + objfrom.options[objfrom.selectedIndex].text+ " = "+ RoundDecimals(dblResult,3) +" " + objto.options[objto.selectedIndex].text;
}
</script>
</head>

<body>
<form id="form1" runat="server">
<div>

<table>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<table border="1" style="border-left-color: #ffed9d; border-bottom-color: #ffed9d;
border-top-color: #ffed9d; border-collapse: collapse; border-right-color: #ffed9d">
<tr>
<th align="left" colspan="2" style="font-size: large; color: #760000; background-color:Gray">
CONVERTER</th>
</tr>
<tr>
<td colspan="2">
Enter a value &amp; choose 'From' and 'To' units then
<br />
press 'Convert' button to get equivalent value.</td>
</tr>
<tr>
<td>
Convert :</td>
<td>
<asp:TextBox ID="txtConvert" runat="server" MaxLength="7" TabIndex="1"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:RegularExpressionValidator ID="REV" runat="server" ControlToValidate="txtConvert"
Display="Dynamic" ErrorMessage="Enter Only Numeric." ValidationExpression="\d{1,7}.*"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td colspan="2">
<asp:RequiredFieldValidator ID="RFV1" runat="server" ControlToValidate="txtConvert"
Display="Dynamic" ErrorMessage="Enter Units To Convert."></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
From :</td>
<td>
<asp:DropDownList ID="ddlFromUnit" runat="server" AutoPostBack="true" TabIndex="2">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="4046856422.4">Acres</asp:ListItem>
<asp:ListItem Value="1">Grounds</asp:ListItem>
<asp:ListItem Value="10000000000">Hectares</asp:ListItem>
<asp:ListItem Value="92903.04">Sq Feet</asp:ListItem>
<asp:ListItem Value="836127.36">Sq Yards</asp:ListItem>
<asp:ListItem Value="1000000">Sq Meters</asp:ListItem>
<asp:ListItem Value="0.002296">Cents</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="2">
<asp:RequiredFieldValidator ID="RFV2" runat="server" ControlToValidate="ddlFromUnit"
Display="Dynamic" ErrorMessage="Enter From Unit."></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
To :</td>
<td>
<asp:DropDownList ID="ddlToUnit" runat="server" TabIndex="3">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="4046856422.4">Acres</asp:ListItem>
<asp:ListItem Value="1">Grounds</asp:ListItem>
<asp:ListItem Value="10000000000">Hectares</asp:ListItem>
<asp:ListItem Value="92903.04">Sq Feet</asp:ListItem>
<asp:ListItem Value="836127.36">Sq Yards</asp:ListItem>
<asp:ListItem Value="1000000">Sq Meters</asp:ListItem>
<asp:ListItem Value="0.002296">Cents</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="2">
<asp:RequiredFieldValidator ID="RFV3" runat="server" ControlToValidate="ddlToUnit"
Display="Dynamic" ErrorMessage="Enter To Unit."></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height: 22px">
Result :</td>
<td style="height: 22px">
<asp:Label ID="lblResult" runat="server"></asp:Label></td>
</tr>
<tr>
<td style="height: 27px">
</td>
<td style="height: 27px">
<asp:Button ID="btnConvert" runat="server" Text="Convert" TabIndex="4"/></td>
</tr>
</table>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>




</div>
k
</form>

</body>
</html>







Post Your Reply Post New Question

 Viewer's Reply
This Question has 0 replies.

 
Sponsored by
Web Application Security — How to Minimize Prevalent Risk of Attacks
Many .NET teams are underperforming, is yours?
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter