Read TextBox input, convert to double and do calculation (C#)
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
void Page_Load()
{
if (Page.IsPostBack)
{
lblTax.Text = "Your tax bill would be $";
lblTax.Text += Convert.ToString(Convert.ToInt32(txtEarnings.Text)*Convert.ToInt32(txtTaxRate.Text)/100);
lblTax.Visible=true;
}
}
</script>
<html>
<head>
<title>Calculate Tax Bill</title>
</head>
<body>
<h3>Tax rates
</h3>
<form runat="server">
Please enter your earnings: $
<asp:TextBox id="txtEarnings" runat="server" width="80px"></asp:TextBox>
<br />
Please enter your tax rate, for example enter '7' for 7%
<asp:TextBox id="txtTaxRate" runat="server" width="30px"></asp:TextBox>
<br />
<asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
<br />
<asp:Label id="lblTax" runat="server" visible="False"></asp:Label>
<br />
</form>
</body>
</html>
Related examples in the same category