检索已禁用的ASP.NET文本框的值

Liz*_*Liz 5 asp.net textbox

我有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;
  }
Run Code Online (Sandbox Code Playgroud)

假设txtPricePad的初始值为0且txtCarton为12.当txtPrice的值更改为1200时,将调用GetPricePerPad(),因此txtPricePad将为100.

Javascript成功地将txtPricePad的值更改为100但是当我从代码隐藏调用txtPricePad时,它的值仍为0.这就是为什么我还将公式的结果分配给HiddenField.还有其他方法吗?我不想再使用HiddenField.

Ica*_*rus 10

Liz,您是否可以将文本字段设为readonly(ReadOnly = True)而不是将其设为Disabled = True?原因是当禁用文本字段时,不会使用POST请求中的表单提交.看到这个问题.

如果你想让它看起来好像被禁用了,我想你可以将CssClass应用于按钮.

  • 我知道这是一年前的事了,但试图恢复一个残疾文本框的价值浪费了整整8小时 - 你的答案有效 (2认同)