开发者

Dynamic control with DevExpress ASPXComboBox has Javascript problems

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 comb开发者_JS百科o.

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?


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?


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:

protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load();
        this.control.DataBind();
    }

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜