在javascript中设置的值无法在服务器端读取 [英] Value set in javascript cant read it on server side

查看:51
本文介绍了在javascript中设置的值无法在服务器端读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的应用程序中有一个简单的客户端计算.
情况就像,

我有3个文本框.说txt1,txt2,txt3.
txt3 = txt1 + txt2

我的javascript工作正常,就像

HI All,

I have a simple client side calculation in my application.
Situation is like,

I have 3 textboxes. Say txt1,txt2,txt3.
txt3 = txt1 + txt2

my javascript works fine which is something like

document.getElementbyID('<%=txt3.ClientID%>').value = Number(document.getElementbyID('<%=txt1.ClientID%>').value) + Number(document.getElementbyID('<%=txt2.ClientID%>').value); 


我在客户端得到结果.但是,当我在服务器端代码中编写txt3.text时,我什么也没得到.

txt3是只读的,我试图将其设置为readonly,但工作正常,但如何将其设置为true呢?

请有人可以帮助我....

在此先感谢您.


I get result on client side. But when i write txt3.text in server side code i get nothing.

txt3 is readonly i tried to make it readonly false and it worked fine but how can I make it with readonly true?

Please some one can help me....

Thanks in advance.

推荐答案

在这里有一个简单的示例可以看到它的工作原理:

DebugQuery.html仅显示查询字符串:
Here''s a simple sample to see that it works:

DebugQuery.html simply shows the query string:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Simple Querystring Debugging</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Just a simple check for the query string!</br>
</body>
<script type="text/javascript">
document.write("<b>Querystring:</b> " + document.location.search);
</script>
</html>



ReadOnly.html包含小型测试HTML标记:



ReadOnly.html contains the small test HTML markup:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onload="init();">
<form id="testForm" method="GET" action="./DebugQuery.html">
    <input ID="test" NAME="realname" VALUE="Hi There" READONLY>
    <input ID="submit" type="submit" name="submit" value="Send!">
</form>
<input ID="doit" type="button" NAME="doIt" VALUE="Set to 10!" onclick="doIt();">
</body>
<script type="text/javascript">
function init()
{
    var test = document.getElementById("test");
    test.value = "0";
}

function doIt()
{
    var element = document.getElementById("test");
    element.value = 10;
}
</script>
</html>



问候,

Manfred



Regards,

Manfred


您需要回发这些字段才能将它们重新存储在服务器上.这也意味着txt3需要成为回发表单的一部分.由于该代码未在此处显示而无法看到,但您可以签出.

祝您好运!
Yo need to post back the fields to get them back on the server. This also means that txt3 needs to be part of the form that is posted back. Can''t see that because that code isn''t shown here but you could check it out.

Good luck!


而不是单引号,请尝试使用双引号
instead of single quotes try doubles quotes
document.getElementbyID("<%=txt3.ClientID%>").value =


这篇关于在javascript中设置的值无法在服务器端读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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