如何从C#获取JAVASCRIPT文本框值 [英] How to get JAVASCRIPT textbox value from C#

查看:67
本文介绍了如何从C#获取JAVASCRIPT文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有三个文本框,在这里,当我更改文本框的值时,它将计算(相乘)该值并在另一个文本框中提供输出.

我的问题是...

当我在文本2中更改值时,将计算适当的值并在文本3中给出值.但是当我从服务器端检索文本3的值时,它仍然是我通过文本2(从JAVASCRIPT生成)更改的较旧的值而不是较新的值. br/>
我的剧本是...



I have three textboxes, here when i change the value of the text box it will calculate(multiply) the value and give output in another textbox.

My problem is...

When i change value in text 2, The appropriate values are calculated and gives in text 3.But while i retrieve text 3 value from server side it remains the older value not newer value which i changed through text 2(generated from JAVASCRIPT).

My Script is...

function GetTotalamt(vat, assess, dis, dischk, net)
 {
 var V = parseFloat(document.getElementById(assess).value) * (parseFloat(document.getElementById(vat).value) / 100);

 var afterV = parseFloat(document.getElementById(assess).value) + parseFloat(V);

 var D = parseFloat(document.getElementById(dis).value);

 document.getElementById(net).value = parseFloat(afterV) - parseFloat(D);

}

推荐答案



试试这个

Hi,

try this

document.getElementById(''<%= txtFName.ClientID %>'').value



其中txtFname是asp.net服务器控件.



where txtFname is asp.net server control


您只更改了客户端文本框中的值(javascript).服务器不会自动获得此更新,因为即使您不希望/不需要它,它也总是会发生.您需要使用该文本框提交表单,以将这些值发布到服务器.然后,服务器代码(c#)可以存储这些值或使用您喜欢的方法执行任何操作.

您可能需要考虑仅存储服务器端文本2的值并重新计算文本3的值.存储计算值通常不是一个好主意,因为它暗示着,它们在大多数情况下都可以轻松地重新计算.

祝你好运!
You only changed the value in the textbox on the client side (javascript). The server won''t get an update on this automatically because it would otherwise always happen, even if you don''t want/need it. You need to submit the form with that textbox to post those values to the server. The server code (c#) can then store those values or do whatever with it you like.

You might want to consider storing only the value of text 2 server side and recalculate the value of text 3. It''s not often a good idea to store calculated values because as it implies, they can be recalculated easily most of the time.

Good luck!


字符串值= Request.Form [[TextBoxID] .UniqueID]

以上对我有用.
string value = Request.Form[[TextBoxID].UniqueID]

The above works for me.


这篇关于如何从C#获取JAVASCRIPT文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆