【发布时间】:2011-08-10 02:24:25
【问题描述】:
我有 3 个 ASP.NET 文本框和一个 HiddenField。 第三个文本框的值(禁用)取决于其他两个文本框的值。
公式是
txtPricepad = txtPrice/txtCarton
<asp:TextBox ID="txtPriceCase" runat="server" onblur="javascript:GetPricePerPad();></asp:TextBox>
<asp:TextBox ID="txtCarton" runat="server"></asp:TextBox>
<asp:TextBox ID="txtPricePad" Enabled="false" runat="server" ></asp:TextBox>
<asp:HiddenField ID="hdPricepad" runat="server"/>
function GetPricePerPad()
{
var priceCase = document.getElementById('ctl00_content_txtPriceCase').value;
var cartons = document.getElementById('ctl00_content_txtCarton').value;
var res = Number(priceCase) / Number(cartons);
document.getElementById('ctl00_content_txtPricePad').value = res;
document.getElementById('ctl00_content_hdPricepad').value = res;
}
假设txtPricePad初始值为0,txtCarton初始值为12。 当 txtPrice 的值变为 1200 时,会调用 GetPricePerPad(),因此 txtPricePad 为 100。
Javascript 成功地将 txtPricePad 的值更改为 100,但是当我从代码隐藏调用 txtPricePad 时,它的值仍然是 0。 这就是为什么我还将公式的结果分配给 HiddenField。还有其他方法可以做到这一点吗?我不想再使用 HiddenField。
【问题讨论】: