[英]How to maintain JavaScript values during PostBack in ASP.Net?
I have written one JavaScript to Calculate the TotalWeight based on two TextBox integer values.我写了一个 JavaScript 来计算基于两个 TextBox integer 值的 TotalWeight。 I multiplied these two values and displayed in the 3rd TextBox Using JavaScript.
我将这两个值相乘并使用 JavaScript 显示在第三个文本框中。 But the problem is, I have one radiobuttonlist, in its selectedindexchanged event, the value I got in the 3rd TextBox gets disappeared.
但问题是,我有一个单选按钮列表,在其 selectedindexchanged 事件中,我在第三个文本框中得到的值消失了。 How to solve this?
如何解决这个问题?
My JavaScript is我的 JavaScript 是
<script type="text/javascript">
function TotalWeight()
{
var D1 = document.getElementById('<%=txtD1.ClientID%>');
var SectionWgt = document.getElementById('<%=txtSectionWeight.ClientID%>');
var TotalWgt = 0*1;
TotalWgt = parseFloat(D1.value) * parseFloat(SectionWgt.value);
if(isNaN(TotalWgt))
document.getElementById('<%=txtTotalWgt.ClientID%>').innerText = "0.000";
else
document.getElementById('<%=txtTotalWgt.ClientID%>').innerText = TotalWgt.toFixed(3);
}
</script>
<asp:TextBox ID="txtD1" runat="server" Width="136px" onkeyup="return TotalWeight();"></asp:TextBox>
use hidden field to store values.使用隐藏字段来存储值。 just use
只需使用
[intput type="hidden" id="someid">] [intput type="hidden" id="someid">]
after that you can use the value using $("#someid").val() Try, this helped me.之后,您可以使用 $("#someid").val() 尝试使用该值,这对我有帮助。
Read the value of the textbox in when the radio button event fires and posts back - and then write it back to the textbox afterwards.在单选按钮事件触发并回发时读取文本框的值 - 然后将其写回文本框。
I would imagine that when the event fires and the page posts back, the third text box reverts to its original value - capture the new value and write it back to the box during the event.我想当事件触发并且页面回发时,第三个文本框恢复到其原始值 - 捕获新值并将其写回事件期间的框中。
After you calculate and assign the value to your Total Textbox, then put that value in a hidden field
as well, and then on postback reassign that value to the textbox from the hidden Field
.在计算并将值分配给 Total Textbox 之后,将该值也放入
hidden field
中,然后在回发时将该值从hidden Field
重新分配给文本框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.