locked
document.selection is undefined when using ComboBox control RRS feed

  • Question

  • User225540144 posted

    Here's the basic code of the control implementation:

        <form id="form1" runat="server">
            <asp:ToolkitScriptManager ID="ScriptManager1" runat="server" CombineScripts="False" EnablePartialRendering="true"></asp:ToolkitScriptManager>
            <ajaxToolkit:ComboBox ID="ComboBox1" runat="server">
                <asp:ListItem Text="[Select an item]" Value="" />
                <asp:ListItem Text="Actual Item #1" Value="SomeValue" />
                <asp:ListItem Text="Actual Item #2" Value="3" />
                <asp:ListItem Text="Actual Item #3" Value="xxx" />
            </ajaxToolkit:ComboBox>
        </form>
    

    Nothing crazy there.

    In IE 10, each time I press a key in the combo box, I'll get a JavaScript exception "0x800a138f - JavaScript runtime error: Unable to get property 'createRange' of undefined or null reference"

    Code reference in the exception is below (in the source code, this is at line 1468 of ComboBox.pre.js)... the underlined and bold line throws it.  document.selection is undefined.

        _getTextSelectionInfo: function (textBox, e) {
    
            var info = new Object();
    
            info.strategy = this._getTextSelectionStrategy();
    
            if (info.strategy == Sys.Extended.UI.ComboBoxTextSelectionStrategy.Microsoft) {
     var userRange = document.selection.createRange();
                    info.selectionStart = 0;
                    info.selectionEnd = textBox.value.length;
                    while (userRange.moveStart('character', -1) != 0) {
                        info.selectionStart++;
                    }
                    while (userRange.moveEnd('character', 1) != 0) {
                        info.selectionEnd--;
                    }

    I've downloaded the latest version of AjaxControlToolkit, and the error persists.

    Anyone have a fix handy?

    Thanks,

    Ken

    Monday, October 14, 2013 7:08 PM

Answers

  • User-417640953 posted

    Ken Cote

    I'm looking to have that Javascript fixed.

     

    Hi Ken,

    Thanks for posting this issue to asp.net forum.

    If you are looking to have that Javascript fixed, I would like to suggest you use document.getSelection() or window.getSelection() to complete it.

    Please refer to below link.

    http://jsfiddle.net/hgDwx/

     

    Thanks.

     

    Best Regards!

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 16, 2013 5:48 AM

All replies

  • User225540144 posted

    No to be be rude, but this doesn't help.  It's a clumsy workaround and can be done without the ComboBox control entirely, using the native DropDownList.  I'm looking to have that Javascript fixed.

    Neither window.getRange() or document.getRange() work, either.  

    Tuesday, October 15, 2013 6:42 AM
  • User-417640953 posted

    Ken Cote

    I'm looking to have that Javascript fixed.

     

    Hi Ken,

    Thanks for posting this issue to asp.net forum.

    If you are looking to have that Javascript fixed, I would like to suggest you use document.getSelection() or window.getSelection() to complete it.

    Please refer to below link.

    http://jsfiddle.net/hgDwx/

     

    Thanks.

     

    Best Regards!

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 16, 2013 5:48 AM
  • User225540144 posted

    Thanks a lot!

    Wednesday, October 16, 2013 9:37 AM