-1
因此,在我的BMI計算器上工作時,似乎無法使計算部分工作。我有三個文本框,其中包含完成計算所需的信息,英尺高度,英寸高度和磅磅。使用事件處理程序的BMI計算器計算
這是我的代碼。什麼似乎是我的錯誤?
<form id="US" runat="server" visible="true">
<div style="background-color:#4DB8FF; width:350px; height:300px; margin:auto; text-align:center; font-family:Arial">
<h4>
Body Mass Index Calculator
<asp:Button id="btnUS" runat="server" text="US" OnClick="btnUS_Click" />
<asp:Button id="btnMetric" runat="server" Text="Metric" OnClick="btnMetric_Click" /> <br />
<script runat="server">
void btnUS_Click(object sender, EventArgs e)
{
this.US.Visible = true;
this.Metric.Visible = false;
}
void btnMetric_Click(object sender, EventArgs e)
{
this.US.Visible = false;
this.Metric.Visible = true;
}
void calcUS_Click(object sender, EventArgs e)
{
string operand1 = heightus.Text;
string operand2 = heightus1.Text;
string operand3 = weightus.Text;
string bmi = resultus.Text;
double number;
bool isOperand1Number = Double.TryParse(operand1, out number);
bool isOperand2Number = Double.TryParse(operand2, out number);
bool isOperand3Number = Double.TryParse(operand3, out number);
if (isOperand1Number && isOperand2Number && isOperand3Number)
{
bmi = (((operand3/((operand1 * 12) + operand2) * (operand1 * 12) + operand2))) * 703);
}
else
{
Response.Write("Please type a numeric value into each of the text boxes.");
}
}
</script>
</h4>
<asp:label ID="lbl1" Text="Height:" runat="server" />
<asp:TextBox ID="heightus" runat="server" />feet<br />
<asp:TextBox ID="heightus1" runat="server" />inch(es)<br />
<asp:Label ID="lbl2" Text="Weight:" runat="server" />
<asp:TextBox ID="weightus" runat="server" />lbs<br />
<br />
<asp:Button ID="calcUS" Text="Calculate" OnClick="calcUS_Click" runat="server" />
<asp:Button ID="clearUS" runat="server" Text="Clear"/>
<br /><br />
<asp:Label ID="lbl3" Text="Results:" runat="server" />
<asp:TextBox ID="resultus" runat="server" /> <br />
</div>
</form>
您能解釋一下您面臨的問題嗎?什麼是不工作等,這將有助於解決您的問題。 – Raman 2013-03-13 19:07:24
首先,您正在設置'bmi',但是您並未將該設置設置爲頁面上的任何內容以查看結果(如'resultus.Text = myResult')。其次,你正在使用字符串進行計算。第三,你應該把所有的代碼移到代碼隱藏中。第四,只需使用JavaScript! – MikeSmithDev 2013-03-13 19:07:45