自定义 SelectedValue 属性

发布于 2024-08-14 15:15:36 字数 677 浏览 9 评论 0原文

我正在创建一个完全自定义的(仅从 WebControl 继承)组合框/下拉列表 搜索控件,具有自动完成 功能。

JQuery 处理为列表项(其中包含字符串的 div)分配 onhover 和 onclick 事件,并处理 Web 服务调用以获取匹配文本的项列表。

服务器处理自定义属性并控制渲染。

问题是我需要实现一个类似于 SelectedValue 的属性,以便当用户从搜索结果中选择一个项目时,该值可以在服务器上用于其他处理。我已经做了几天的研究,但还没有找到一种清晰、简洁的方法来处理回发数据。

我确实读过一篇博客,其中提到实现 IPostBackDataHandler 接口,但是 RaisePostDataChangeEvent() 的实现需要调用服务器方法(例如 SelectedIndexChange)我目前没有实施。

public void RaisePostDataChangedEvent()
{
    this.SelectedIndexChanged(EventArgs.Empty);
}

现在的问题是:有人对处理这个问题有建议吗?或者我最好简单地继承下拉列表控件并覆盖现有功能?

我觉得我缺少一个可以将这一切组合在一起的非常小的部分。

I am creating a completely custom (only inherits from WebControl) combobox/dropdownlist search control with autoComplete capabilities.

JQuery handles assigning the onhover and onclick events for list items (divs with strings in them) and handles the web service call for getting the list of items for the matching text.

The server handles the custom attributes and control rendering.

The issue is that I need to implement a property that is similar to SelectedValue so that when a user selects an item from the search results, the value can be used on the server for other processing. I have done days of research but have not found a clear, concise way of handling the post back data.

I did read a blog that mentioned implementing the IPostBackDataHandler interface, but the implementation of RaisePostDataChangeEvent() calls for calling a server method (like SelectedIndexChange) that I am not implementing at the moment.

public void RaisePostDataChangedEvent()
{
    this.SelectedIndexChanged(EventArgs.Empty);
}

Now for the question: Does anyone have advice for handling this? Or am I better off simply inheriting from the dropdownlist control and overriding the existing functionality?

I feel like I'm missing a very small piece that will fit this all together.

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

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

发布评论

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

评论(1

雨落□心尘 2024-08-21 15:15:36

您是否考虑过从微软的源服务器上拉下源代码并看看他们是如何实现 DropDownList 的?这将使您了解他们如何解决问题的绑定和事件部分,并让您很好地了解它在其他方面的作用。通过这种方式,您可以决定是否要继承它,或者是否可以借用他们如何实现 IPostBackDataHandler 的一些想法。

由于我不知道你具体在做什么,所以我无法建议你是否应该从下拉菜单继承,但根据我对你正在做的事情的印象,我会说你可能不这样做。

您也可以查看 AjaxControlToolkit 的源代码,因为它有类似的组件。同样,您可以获得有关如何处理这些特定事物的想法,并根据您自己的需要进行调整。

Have you considered pulling down the source code from Microsoft's source server and taking a look at how they implemented DropDownList? This would allow you so see how they solved the binding and events part of the problem and give you a good idea what it does otherwise. This way you can decide if you want to inherit from it, or if you can just borrow some ideas for how they implemented IPostBackDataHandler.

Since I have no idea what specifically you are doing, I couldn't advise you if you should inherit from dropdown as it is, but based on my impressions of what you are doing I'd say you probably don't.

Also you might look at source from the AjaxControlToolkit as it has a similar component. Again, you can get ideas for how these specific things are handled and adapt them to your own needs.

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