如何在服务器端使用客户端文本框 [英] How to use client side textbox in serverside

查看:70
本文介绍了如何在服务器端使用客户端文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI朋友们,请尝试下面的资源;我用于自动计算的javascript;
我想要服务器端的t1,t2,t3控件进行进一步的编码.
例如:我希望此t3值在按钮单击事件上标记;

HI friends,Try the source below;The javascript i used for automatic calculation;
i want the t1,t2,t3 controls in server side for further coding.
For eg:I want this t3 value to label on button click event;

报价:

< html xmlns ="http://www.w3.org/1999/xhtml">
< head runat ="server">
< script type ="text/javascript">
函数nims(){

var a = parseFloat(document.form1.t1.value);
var b = parseFloat(document.form1.t2.value);
var sum = a + b;
document.form1.t3.value = sum;
}
</script>

< title> </title>
</head>
< body>
< form id ="form1" runat ="server">

< input type ="text" value ="0" name ="t1" onkeyup ="nims();" />
< input type ="text" value ="0" name ="t2" onkeyup ="nims();"/>
<输入type ="text" value ="0" name ="t3"/>


</form>
</body>
</html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function nims() {

var a = parseFloat(document.form1.t1.value);
var b =parseFloat(document.form1.t2.value);
var sum = a + b;
document.form1.t3.value = sum;
}
</script>

<title> </title>
</head>
<body>
<form id="form1" runat="server">

<input type="text" value="0" name="t1" onkeyup="nims();" />
<input type="text" value="0" name="t2" onkeyup="nims();"/>
<input type="text" value="0" name="t3" />


</form>
</body>
</html>

推荐答案

可以在其中添加runat ="Server"标签吗?
Can you add runat="Server" tag there?


如果要访问服务器端的控件进行任何计算,必须将控件标记为"runat=server".

基于更改,您当然也必须更改Javascript代码.当前的实现基于客户端html控件,但是一旦将runat属性添加到控件中,访问它们的方式就会改变.更改后,使用<%= myControl.ClientID %>在JavaScript中访问客户端上的控件.
If you want to access the controls on the server side for any calculation, you have to mark the controls as ''runat=server''.

Based on the change, you surely have to change the Javascript code too. Current implementation is based on client side html controls, but once you add the runat property to the controls, the way to access them will change. Use <%= myControl.ClientID %> to access the control on client side in JavaScript after the change.


这篇关于如何在服务器端使用客户端文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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