我有3個ASP.NET文本框和一個HiddenField。 第三個文本框的值(禁用)取決於其他兩個值。檢索禁用的ASP.NET文本框的值
的公式是
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。
可能重複的[我想獲得在我們的下一個jsp中禁用的文本框的值,但我得到空值](http://stackoverflow.com/questions/3757806/i-want-to-獲得值的禁用文本框在我們的下一個jsp但我是得到NU) –