简体   繁体   English

我通过 jquery 将值粘贴到文本框,但我无法从后面的代码中获取此值

[英]I paste value to textbox by jquery but i can't get this value from behind code

There are 3 asp:Textbox Using keyup in jquery to paste value to 3th asp:TextBox from 2 asp:TextBox before.有 3 个 asp:Textbox 在 jquery 中使用 keyup 将值从之前的 2 个 asp:TextBox 粘贴到第 3 个 asp:TextBox。 (asp:Textbox 1 + asp:Textbox 2) (asp:文本框 1 + asp:文本框 2)

<asp:TextBox runat="server" ID="Total" CssClass="form-control"></asp:TextBox>

ex:前任:

result = parseFloat(txt1) + parseFloat(txt2) 
$('input[id*=Total]').val(result);

in view: txt3 is 10在视图中:txt3 是 10

But in behind code I can't get value from 3th asp:TextBox但是在后面的代码中,我无法从第 3 个 asp:TextBox 中获得价值

Your asp element should have runat="server" so that it can be referenced from code behind.你的 asp 元素应该有runat="server"以便它可以从后面的代码中引用。

Note that when you use runat="server" the id is auto-generated so you need to specify the clientIDMode to make it static .请注意,当您使用runat="server" ,id 是自动生成的,因此您需要指定clientIDMode以使其成为static

<asp:TextBox ID="txtBox" runat="server" ClientIDMode="Static"></asp:TextBox>

Also, if you don't want ClientIDMode to be static you can still reference the asp Element like following:此外,如果您不希望 ClientIDMode 是静态的,您仍然可以像下面这样引用 asp 元素:

$('#<%=txtBox.ClientID%>').xxx();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM