Skip to main content
 首页 » 编程设计

c#之javascript 函数 "$find"是否特定于 asp.net webforms 中的 telerik 客户端对象

2024年02月13日29softidea

正如问题所指出的,我想知道 javascript 函数“$find”是否只是因为它由 telerik 控件提供而起作用,或者它是否实际上是我可以使用的 webforms 东西。

我知道 $get 是 document.getElementById 的快捷方式,但我想知道 $find 是否由 webforms 提供。如果是这样,我会对如何将客户端对象注册到特定控件 ID 非常感兴趣。

到目前为止,我已将 scriptControl.find("id") 用于我的自定义项(其中 scriptControl 由我提供)。但是,如果有一种更标准的方法可以通过 $find 访问所有客户端对象,我会更喜欢那样。

编辑: 在 Firebug 的帮助下挖掘 MS Code 揭示了这一点:

function Sys$_Application$findComponent(id, parent) { 
/// <summary locid="M:J#Sys.Application.findComponent" /> 
/// <param name="id" type="String"></param> 
/// <param name="parent" optional="true" mayBeNull="true"></param> 
/// <returns type="Sys.Component" mayBeNull="true"></returns> 
var e = Function._validateParams(arguments, [ 
  {name: "id", type: String}, 
  {name: "parent", mayBeNull: true, optional: true} 
]); 
 
if (e) throw e; 
 
return (parent ? 
 ((Sys.IContainer.isInstanceOfType(parent)) ? 
   parent.findComponent(id) : 
   parent[id] || null) : 
   Sys.Application._components[id] || null); 
} 

做类似的事情

Sys.Application._components["id"] = {clientobject};  

似乎是一个相当 hacky 的解决方案。

有什么建议吗?

请您参考如下方法:

$get 和 $find 都不是 Telerik 特定的。它们包含在 ASP.NET Ajax 库中。 $find 是 Sys.Application.findComponent(id, parent) ( reference ) 的快捷方式,所以只要这个库包含在这一页。例如代替

scriptControl.find("id") 

你可以做到

$find("id") 

请注意,$find 仅在已注册的组件中搜索,即那些使用 Sys.Application.addComponent(component) 方法添加到 Application 实例的组件。