如何在ASP.NET上使用JavaScript设置文本框的值 - javascript

我需要使用来自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“名称'AddressTextBox'在当前上下文中不存在”

有任何想法吗?谢谢。

javascript大神给出的解决方案

AddressTextBox是服务器控件,因此可能会更改ID。
 试试:

var dst = document.getElementById("<%=AddressTextBox.ClientID%>").value;

这样可以解决您的错误。

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

如何从客户端将数据插入数据库? - javascript

我是Web开发的初学者,可以访问cpanel上托管的网站,并且需要对其进行一些更改。这个网站的后端是由蛋糕PHP制作的,我想使用ajax从客户端将一些数据插入其数据库。问题是我不知道如何获取负责插入数据库的PHP文件的URL。参见下面的代码:var xhttp = newXMLHttpRequest(); xhttp.onreadystatechange= …

执行onclick时获得意外令牌 - javascript

我正在使用onclick事件从PHP调用JS函数。这是我的代码:我在一个函数中,因此我需要通过PHP来完成它,因为然后我会返回:$html = '<input type="checkbox" checked value="1" id="setGetSku" name="se…

LinkBut​​ton OnClick不能与数据目标和数据切换一起运行 - javascript

在我的asp.net应用程序(使用C#)中,我具有以下链接按钮:<asp:LinkButton ID="btnSelectPhoto" runat="server" Width="120" style="display:inline-block; margin:5px;" …

为HTML表单GET方法添加其他文本 - javascript

使用表单的“ get”方法时,<form action="domain.com" method="get"> Surname: <input type="text" name="ABC"><br> Name: <input type=&#…