如何更改 AutoCompleteExtender 客户端 (javascript) 的 TargetControlID?

发布于 2024-11-08 06:31:59 字数 287 浏览 0 评论 0原文

通常,我可以使用如下方式设置 TargetControlID 服务器端:

    AutoCompleteExtender ace = new AutoCompleteExtender();
    ace.ID = "AutoCompleteExtender1";
    ace.TargetControlID = "whatever";

我知道如何获取 AutoCompleteExtender 客户端,但我也在寻找一种更新 TargetControlID 客户端的方法。有什么想法吗?

Normally, I can can set the TargetControlID server side using something like this:

    AutoCompleteExtender ace = new AutoCompleteExtender();
    ace.ID = "AutoCompleteExtender1";
    ace.TargetControlID = "whatever";

I know how to grab the AutoCompleteExtender client side, but I am looking for a method to update the TargetControlID client side too. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝颜夕 2024-11-15 06:31:59

遗憾的是,这对于现有的 AutoCompleteExtender 实例来说是不可能的。您可能对以下几种方法感兴趣,

var x = $find("AutocompleteBehaviorID");//find the instance

x.get_completionListElementID();//get the ID of target textbox

x.set_completionListElementID();//set the ID of target textbox has no effect though :(

x._completionListElement();//direct access to DOM element that acts as target

这里的问题似乎是初始化版本在控制工具包的 init 阶段将附加事件附加到目标文本框(是的,客户端也有一个 init阶段)。当初始化版本更改为目标时(如您想要的那样),则不会添加这些事件 keypressblur 等,因此您看不到任何更改。但如果您了解 javascript,您可以执行以下操作,使其适用于任何文本框。

$create(Behavior,{properties},{events},interfaces,target);

其中

Behavior

AjaxControlToolkit.AutoCompleteBehavior

属性

是一个 javascript 对象,如下所示(还有更多属性,但这些就足够了

{
    "completionInterval": 1,
    "completionListElementID": "empty panel id",
    "completionListItemCssClass": "css class name",
    "delimiterCharacters": ";",
    "highlightedItemCssClass": "css class name",
    "id": "CLIENTSIDEID",
    "minimumPrefixLength": 1,
    "serviceMethod": "WebMethodName",
    "servicePath": "AbsolutePath to asmx file"
}

事件

还有更多可用的事件

{
    "itemSelected": jsFn,
    "populated": jsFn
}

目标

所有的事件、花哨的东西都吸引到这个文本框了

目标元素是最重要的,现在 一切都结束了,你可以一直通过javascript初始化一个自动完成的实例,只要确保ID已经不存在即可。

Well sadly this is not possible for existing instance of AutoCompleteExtender. There are a few methods that you might be interested in like below

var x = $find("AutocompleteBehaviorID");//find the instance

x.get_completionListElementID();//get the ID of target textbox

x.set_completionListElementID();//set the ID of target textbox has no effect though :(

x._completionListElement();//direct access to DOM element that acts as target

the problem here seems initialized version attaches additional events to target textbox during init phase of the control toolkit( yeah client side too has a init phase). When a initialized version is made to change as the target (as you wanted to do) then these events keypress,blur etc are not added hence you don't see any changes. But if you knew javascript you can do the below to make it work with any textbox.

$create(Behavior,{properties},{events},interfaces,target);

where

Behavior

AjaxControlToolkit.AutoCompleteBehavior

properties

is a javascript object as below (there are more properties but these suffice

{
    "completionInterval": 1,
    "completionListElementID": "empty panel id",
    "completionListItemCssClass": "css class name",
    "delimiterCharacters": ";",
    "highlightedItemCssClass": "css class name",
    "id": "CLIENTSIDEID",
    "minimumPrefixLength": 1,
    "serviceMethod": "WebMethodName",
    "servicePath": "AbsolutePath to asmx file"
}

Events

there are more events available

{
    "itemSelected": jsFn,
    "populated": jsFn
}

The Target

Target element is the most important. It is this text box that all the events ,bells and whistles attracted to.

$get("ELEMENT ID")

now that is all over , you can initialize a instance of auto complete though javascript all the time. Just make sure the ID already does not exist.

柏拉图鍀咏恒 2024-11-15 06:31:59

显然微软认为这并不重要,所以目前没有办法做到这一点:)

Apparently Microsoft didn't think was important, so there is not a way to do this at this time :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文