简体   繁体   English

$ find RadWindowManager对象始终返回null值

[英]$find RadWindowManager object is always returned null value

I have a strange problem and I can not understand the reason why it is happening. 我有一个奇怪的问题,我无法理解它发生的原因。

In the same *.ascx file, I declare a Telerik:RadWindowManager control and then I call $find() to find that RadWindowManager. 在同一个* .ascx文件中,我声明一个Telerik:RadWindowManager控件,然后调用$find()查找该RadWindowManager。 However, the method always returns a null value. 但是,该方法始终返回空值。

Here is the code (included in the same *.ascx): 这是代码(包含在同一* .ascx中):

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<script type="text/javascript">
function init(){
    GetRWndManager();
}

function GetRWndManager() {
    return $find("<%=rwndManager.ClientID%>"); //return null at this step
}

</script>
<telerik:RadWindowManager ID="rwndManager" runat="server" ShowContentDuringLoad="False" VisibleOnPageLoad="False" EnableShadow="true">
</telerik:RadWindowManager>

Ensure you call the init() function (actually, the GetRWndManager() function) after the Sys.Application.Load event, because IScriptControl client-side objects may not be created before that: http://msdn.microsoft.com/en-us/library/bb383829.aspx . 确保在Sys.Application.Load事件之后调用init()函数(实际上是GetRWndManager()函数),因为在此之前可能未创建IScriptControl客户端对象: http : //msdn.microsoft.com/en -us / library / bb383829.aspx

Here is an example: 这是一个例子:

function init() {
    GetRWndManager();
    Sys.Application.remove_load(init);
}
Sys.Application.add_load(init);

function GetRWndManager() {
    return $find("<%=rwndManager.ClientID%>");
}

Or, use setInterval() and check whether you got an object, until you get an object or reach a maximum of, let's say, 200 attempts. 或者,使用setInterval()并检查是否有对象,直到获得一个对象或达到最大200次尝试为止。

Also, consider making the function names unique in the UCs to prevent them from overriding each other when there are several instances on the page. 另外,请考虑使函数名称在UC中唯一,以防止页面上有多个实例时它们相互覆盖。 The following KB will give you a neat idea: http://www.telerik.com/support/kb/aspnet-ajax/details/using-dynamic-unique-names-for-javascript-functions . 以下知识库将为您提供一个巧妙的想法: http : //www.telerik.com/support/kb/aspnet-ajax/details/using-dynamic-unique-names-for-javascript-functions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM