2つのテキストボックス値を計算し、3番目のテキストボックスに正常に表示しましたが、textbox1に値を入力してtextbox2に移動すると問題が発生します。 = "true" textbox1とtextbox2に対して、このAutoPostBack = "true"を削除すると、計算された値は3番目のテキストボックスに表示されません。ここで2つのテキストボックス値の計算値を3番目のテキストボックスに表示
はここ
protected void txttotal_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txttotal.Text) && !string.IsNullOrEmpty(txtdiscount.Text))
txtgrandtotal.Text = (Convert.ToInt32(txttotal.Text) - Convert.ToInt32(txtdiscount.Text)).ToString();
}
protected void txtdiscount_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txttotal.Text) && !string.IsNullOrEmpty(txtdiscount.Text))
txtgrandtotal.Text = (Convert.ToInt32(txttotal.Text) - Convert.ToInt32(txtdiscount.Text)).ToString();
}
の背後に私のコードは、ASPXコード
<asp:TextBox ID="txttotal" runat="server" CssClass="textstyle" OnTextChanged="txttotal_TextChanged" AutoPostBack="true"></asp:TextBox>
<asp:TextBox ID="txtdiscount" runat="server" CssClass="textstyle" OnTextChanged="txtdiscount_TextChanged" AutoPostBack="true"></asp:TextBox>
<asp:TextBox ID="txtgrandtotal" runat="server" CssClass="textstyle" ReadOnly="true"></asp:TextBox>
サイド注:これは、クライアント側のコード(Javaスクリプト)も優れています。 – user3185569
ページが毎回リロードされないようにするには、自動ポストバックを削除します。次に、ボタンを使用してサーバーにポストバックします。正直なところ、これはこの操作のために過剰です。 JavaScriptは完全に2つの数値を追加することができます。このためにサーバで前後にすべてを行う必要はありません。 – David