telerik RadComboBox find Returns null - why?

LostLord picture LostLord · Nov 1, 2010 · Viewed 7.2k times · Source

why the below javascript code always returns null (mean alert) ?

<%@ 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>

thanks in future advace best regards

Answer

Brian Mains picture Brian Mains · Nov 1, 2010

try:

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

Certain scripts need to run/load first before $find will work.