2010-11-01 170 views
1

爲什麼下面的JavaScript代碼總是返回空(平均值警報)?telerik RadComboBox查找返回null - 爲什麼?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %> 

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> 
    </telerik:RadScriptManager> 
    <div> 
     <telerik:RadComboBox ID="RadComboBox1" runat="server"> 
     </telerik:RadComboBox> 
    </div> 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> 
     <script type="text/javascript"> 
      var combo = $find("<%= RadComboBox1.ClientID %>"); 
      alert(combo); 
     </script> 
    </telerik:RadCodeBlock> 
    </form> 
</body> 
</html> 

感謝在未來advace 問候

回答

4

嘗試:

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> 
    <script type="text/javascript"> 
     function pageLoad() { 
      var combo = $find("<%= RadComboBox1.ClientID %>"); 
      alert(combo); 
     } 
    </script> 
</telerik:RadCodeBlock> 

某些腳本需要運行/加載之前先找到$將工作。

+6

哪些腳本? – CRice 2011-12-16 01:40:12