【发布时间】:2016-11-09 04:16:18
【问题描述】:
我需要使用来自 javascript 输入的值设置 asp 文本框。
我在这里:
<td ><asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' ClientIDMode="Static" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="AddressTextBox" ErrorMessage="*"
ValidationGroup="InsertCustomer" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
我使用来自here 的自动完成地址表单
所以我把它放到了 javascript 代码中:
var src = document.getElementById("autocomplete");
var dst = document.getElementById("AddressTextBox");
这个函数fillInAddress()函数:
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
dst.value = src.value;
}
我试图在选择地址后立即从自动完成获取地址文本框字段的完整地址。
但我收到一个错误,即 AddressTextBox“当前上下文中不存在名称'AddressTextBox'”
有什么想法吗?谢谢。
【问题讨论】:
-
那个错误一定来自服务器端,JavaScript 不会写这样的错误。
-
没有看到整个代码
AddressTextBox可能是另一个控件的子控件,您必须遍历每个控件控件才能根据 id 名称查找。
标签: javascript c# jquery asp.net google-maps