Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用$get ASP.NET获取错误vhen_Javascript_Asp.net - Fatal编程技术网

Javascript 使用$get ASP.NET获取错误vhen

Javascript 使用$get ASP.NET获取错误vhen,javascript,asp.net,Javascript,Asp.net,嗨,在我的主页中,我插入了以下javascript <head runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> <link rel="Stylesheet" type="text/css" href="css/MainStyle.css" /> <scr

嗨,在我的主页中,我插入了以下javascript

<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link rel="Stylesheet" type="text/css" href="css/MainStyle.css" />
<script type = "text/javascript">

function ClientItemSelected(sender, e) {
    $get("<%=hfCustomerId.ClientID %>").value = e.get_value();

}

功能ClientItemSelected(发件人,e){
$get(“”).value=e.get_value();
}

在我的内容页中,我有一个AutoCompleteXtender这是代码

<asp:TextBox ID="txtCustomer" runat="server">
      </asp:TextBox>
      <ajx:AutoCompleteExtender ServiceMethod="SearchCustomers" MinimumPrefixLength="2"
          CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="txtCustomer"
          ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false" OnClientItemSelected="ClientItemSelected">
      </ajx:AutoCompleteExtender>
      <asp:HiddenField ID="hfCustomerId" runat="server" />
       <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
          onclick="btnSubmit_Click"  />

但是当我编译的时候,我得到了这个错误

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. 
Please review the following specific error details and modify your source code
appropriately. 

Compiler Error Message: CS0103: The name 'hfCustomerId' does not exist in the current context

Source Error:
Line 11:     <script type = "text/javascript">
Line 12:     function ClientItemSelected(sender, e) {
Line 13:         $get("<%=hfCustomerId.ClientID %>").value = e.get_value();
Line 14:         
Line 15:     }
编译错误
描述:编译服务此请求所需的资源时出错。
请查看以下特定错误详细信息并修改源代码
适当地。
编译器错误消息:CS0103:当前上下文中不存在名称“hfCustomerId”
源错误:
第11行:
第12行:功能ClientItemSelected(发送方,e){
第13行:$get(“”).value=e.get_value();
第14行:
第15行:}

我遗漏了什么?

hfCustomerId
在aspx页面中,而不是粘贴页面中,因此您无法直接引用它


这里有一个指南:

在内容页上用javascript声明一个变量,其中实际控件(id为hfCustomerId的隐藏字段)存在,如下所示:

 var ddlFldDataID = $("<%= ddlFldData.ClientID %>");

请注意,您必须已经引用了jquery。

是否可以将我的js脚本放在内容页中..?是的,它是完全有效的。
function ClientItemSelected(sender, e) {
    $('#' + ddlFldDataID.selector).val() = e.get_value();
}