使用 DevExpress ASPXComboBox 进行动态控制存在 Javascript 问题
我对 Dev Express 组件(即 AspxComboBox)有问题。
我的上下文是这样的:我想为我的一些业务实体动态生成接口。我设计了一个用户控件,它接收一些元数据,并根据该元数据,控件向界面添加文本框、日期编辑器和组合框。当所有这些控件以非动态方式添加到页面时,它们的工作方式就像一个魅力。 但是,当我从 C# 代码添加它们时,以下 Javascript 行出现错误:
document.getElementById("usercontrol_combo_I").setAttribute("autocomplete", "off");
“usercontrol”是我正在设计的用户控件的 ID。 “combo”是组合的 ID。
错误是在 HTML DOM 中找不到具有 ID(“usercontrol_combo_I”)的元素。
我发现,如果我选择不在组合本身上使用 DataBind(注释掉对 AspxComboBox 实例的 DataBind() 方法的任何调用),则永远不会呈现有错误的 JS 行(最终不会出现在HTML)。但是,如果我这样保留它,任何后续回发都会清空组合列表(组合中没有更多项目)。组合的数据源是在每次页面加载时分配的 IList 实例(即使 PostBack == true)。
DevExpress 支持论坛上有一篇帖子报告了同样的问题,但是,团队没有给出答复。
这里有人遇到过这个问题并找到解决方法吗?
I have a problem with a Dev Express component, namely AspxComboBox.
My context is this: I want to dynamically generate the interface for some of my business entities. I have designed a user-control that receives some metadata and, based on that metadata, the controls adds text boxes, date-editors and combo boxes to the interface. All of those controls work like a charm when they are added to the page in a non-dynamic manner.
However, when I add them from the C# code, the following Javascript line has an error:
document.getElementById("usercontrol_combo_I").setAttribute("autocomplete", "off");
"usercontrol" is the ID of the user control I'm designing. "combo" is the ID of the combo.
The error is that the element with the ID ("usercontrol_combo_I") is not to be found in the HTML DOM.
I've discovered that if I choose not to use DataBind on the combo itself (comment out any call to the DataBind() method of the AspxComboBox instance), the JS line that has the error is never rendered (is not present in the final HTML). But, if I leave it like that, any subsequent PostBacks empties the combo list (there are no more items in the combo). The datasource of the combo is a IList instance that is assigned on every page load (even if PostBack == true).
There is a post on DevExpress's support forum that reports the same problem, but, there is no answer from the team.
Anybody here had this problem and found a way to solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 ASP.NET Dev,如果要绑定 Page_Load 事件,则需要将所有请求绑定回服务器,这也包括回调。
现在不支持获取 HTML 元素并设置其属性。关闭自动完成功能的唯一受支持的方法是将回调发送到服务器并关闭服务器端属性上的自动完成功能,这将更新控件。现在,组合框必须是执行回调或将框包装在 CallbackPanel 中的组合框。
您是否也设置了 ASPxComboBox 的 ClientInstanceName?
With ASP.NET Dev if you're binding on the Page_Load events, you need to bind in ALL requests back to the server, this includes Callbacks as well.
Now getting the HTML element and setting its attributes isn't supported. The only supported way to turn autoComplete off is for a callback to be sent to the server and turn off autoComplete on the server-side property which will update the control. Now the comboBox MUST be the one to perform the callback or wrap the box in a CallbackPanel.
Are you setting the ClientInstanceName of the ASPxComboBox too?
事实上,我刚刚找到了一个简单的解决方法。
如果我只是在页面本身的 page_load 事件中对生成的控件调用 DataBind(),问题就消失了。
例如:
其中“control”是包含组合框的 UserControl。
奇怪的是,我什至在 PostBack 和 CallBack 上也调用 DataBind。
但是,嘿,它有效。
我想在使用 Devexpress 时我还错过了一些事情。
但“熟能生巧”!
感谢您的回复。
Actually, I've just found a simple workaround.
If I just call DataBind() on my generated control in the page_load event of the page itself, the problem is gone.
For example:
Where "control" is a UserControl that contains the combobox.
The weird thing is that I call DataBind even on PostBack and CallBack.
But, hey, it works.
I suppose that there are still a couple more things that I miss when using Devexpress.
But "practice makes perfect" !
Thanks for the reply.