asp.net - 检索禁用的 ASP.NET 文本框的值

标签 asp.net textbox

我有 3 个 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。

最佳答案

Liz,您是否可以将文本字段设置为只读(ReadOnly=True)而不是使其Disabled=True?原因是当文本字段被禁用时,不会随 POST 请求中的表单一起提交。 See this question.

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

关于asp.net - 检索禁用的 ASP.NET 文本框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7005217/

相关文章:

Javascript 根据另一个文本框的输入更新文本框

vb.net - 使用文本框自动完成

java - 使用递增和递减按钮在 java Swing 中创建一个数字文本框

android - 按钮并与android bundle 在一起以更改文本,应用程序崩溃

c# - 在不重定向的情况下追加查询字符串

jquery - JQGrid加载下拉列表数据

c# - 如何容纳移动设备

asp.net - 如何在asp.net中传递加密的查询字符串

javascript - 一段时间后如何更改图像背景?

javascript - 使用 JavaScript 使文本框可编辑