代码之家  ›  专栏  ›  技术社区  ›  James Black

AsyncFileUpload在AjaxControlToolkit中存在逻辑错误,当组件位于其他选项卡中时,因此未显示

  •  3
  • James Black  · 技术社区  · 15 年前

    我正在使用AjaxControlToolkit的Nov版本,我发现了一个逻辑错误,但我正在努力找出最好的方法来解决这个问题,在周六之前,这样程序就可以在IE上运行了。

    这个问题只在IE上有一个错误,它在Firefox3.5上工作。

    AsyncFileUpload.pre.js ,在功能上 _app_onload ,这一行: this._innerTB.style.width = (this._inputFile.offsetWidth - 107) + "px";

    我不想从源代码处编译它,但这可能是我的最佳选择,因此我可以修复错误。

    但是,这可能是我的解决办法: this._innerTB.style.width = ((this._inputFile.offsetWidth == 0) ? 200 : this._inputFile.offsetWidth) - 107) + "px";

    但是,我不知道是否有更好的解决办法。

    但是,我试图找出是否有一种方法让一个元素知道它刚刚变得可见,因为任何时候你需要知道一个元素的实际宽度,那么你就不能真正设置它,直到它显示出来。我想不出一个方法来知道这一点,所以我倾向于在第一次选择选项卡时修复选项卡上的元素,但是,对于通用库来说,这不是一个可能的解决方案。

    主要问题的位置

    所以,在我提交一份关于这个问题的bug报告之前,我很好奇是否有 这是一种更好的方法,而不是在页面加载后进行,并假设最小宽度 这可能是错误的<——问题就在这里

                       <cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
                            OnClientUploadError="uploadError" OnClientUploadStarted="StartUpload" 
                            OnClientUploadComplete="UploadComplete" 
                            CompleteBackColor="Lime" UploaderStyle="Modern" Width="400px"
                            ErrorBackColor="Red" ThrobberID="Throbber"  
                            onuploadedcomplete="AsyncFileUpload1_UploadedComplete" 
                            UploadingBackColor="#66CCFF" />
    

    如果这有什么不同的话,我使用它是因为ToolkitScriptManager似乎引入了其他错误,但这可能是我的错误:

    <ajax:AjaxScriptManager ID="scriptmanager1" runat="server" EnablePartialRendering="true" ></ajax:AjaxScriptManager>
    

    我不确定 LoadScriptsBeforeUI

    我发现有趣的是,当dom树完成时,我设置的宽度实际上并没有设置。

    4 回复  |  直到 15 年前
        1
  •  3
  •   googi    14 年前

    尝试将此属性添加到scriptmanager

    LoadScriptsBeforeUI=“true”

    然后我将这个属性添加到scriptmanager,它可以工作!!

    如果您想更改源代码,请查看此页了解详细信息 http://ajaxcontroltoolkit.codeplex.com/SourceControl/network/Forks/keyoke/AyncFileUploadFix/changeset/changes/30da4b8d1c6d

        2
  •  1
  •   Bat_Programmer    11 年前

    这是对我有效的解决方案:

    1. ajaxToolkit:AsyncFileUpload 比如“imageUploaderField”

    2. .imageUploaderField input{width:100%!important;}

    资料来源: http://ajaxcontroltoolkit.codeplex.com/workitem/27429

        3
  •  0
  •   James Black    15 年前

    这不是一个理想的解决方案,但它确实有效,希望有人会有一个更好的解决方案,因为这是我无法提交来修复错误的东西。我将此添加到我的一个javascript文件中,但这是一个黑客行为,不是一个好的解决方案。我不得不替换第二个函数,因为我注释掉了那行。

    $(document).ready(function() {
        Sys.Extended.UI.AsyncFileUpload.prototype._app_onload = function(sender, e) {
            this.setThrobber(false);
            if (this._inputFile != null) {
                if (this._onchange$delegate == null) {
                    this._onchange$delegate = Function.createDelegate(this, this._onchange);
                    $addHandlers(this._inputFile, {
                        change: this._onchange$delegate
                    });
                }
                if (Sys.Browser.agent == Sys.Browser.Firefox) {
                    this._inputFile.size = 0;
                    var width = this._inputFile.offsetWidth;
                    this._inputFile.style.width = "";
                    while (this._inputFile.offsetWidth < width) {
                        this._inputFile.size++;
                    }
                }
                if (this._innerTB != null) {
                    this._inputFile.blur();
                    var inputFile = this._inputFile;
                    setTimeout(function() { inputFile.blur(); }, 0);
                    this._innerTB.style.width = ((this._inputFile.offsetWidth == 0 ? 200 : this._inputFile.offsetWidth) - 107) + "px";
                    this._inputFile.parentNode.style.width = this._inputFile.offsetWidth + "px";
                    if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
                        this._onmouseup$delegate = Function.createDelegate(this, this._onmouseup);
                        $addHandlers(this._inputFile, {
                            mouseup: this._onmouseup$delegate
                        });
                    }
                }
            }
        };
    
        Sys.UI.DomEvent.prototype._removeHandler = function (elements, eventName, handler) {
            Sys._queryAll(elements, function(element) {
                var browserHandler = null;
    //            if ((typeof (element._events) !== 'object') || !element._events) throw Error.invalidOperation(Sys.Res.eventHandlerInvalid);
                var cache = element._events[eventName];
                if (!(cache instanceof Array)) throw Error.invalidOperation(Sys.Res.eventHandlerInvalid);
                for (var i = 0, l = cache.length; i < l; i++) {
                    if (cache[i].handler === handler) {
                        browserHandler = cache[i].browserHandler;
                        break;
                    }
                }
                if (typeof (browserHandler) !== 'function') throw Error.invalidOperation(Sys.Res.eventHandlerInvalid);
                if (element.removeEventListener) {
                    element.removeEventListener(eventName, browserHandler, false);
                }
                else if (element.detachEvent) {
                    element.detachEvent('on' + eventName, browserHandler);
                }
                cache.splice(i, 1);
            });
        }
    
        4
  •  0
  •   keyoke    14 年前

    我的解决方案。。。也许不是最好的,但很有效。

     _app_onload: function(sender, e) {
        this.setThrobber(false);
        if (this._inputFile != null) {
            if (this._onchange$delegate == null) {
                this._onchange$delegate = Function.createDelegate(this, this._onchange);
                $addHandlers(this._inputFile, {
                    change: this._onchange$delegate
                });
            }
            if (Sys.Browser.agent == Sys.Browser.Firefox) {
                this._inputFile.size = 0;
                var width = this._inputFile.offsetWidth;
                this._inputFile.style.width = "";
                while (this._inputFile.offsetWidth < width) {
                    this._inputFile.size++;
                }
            }
            if (this._innerTB != null) {
                this._inputFile.blur();
                var inputFile = this._inputFile;
                setTimeout(function() { inputFile.blur(); }, 0);
                if ((this._inputFile.offsetWidth - 107) >= 1) {
                    this._innerTB.style.width = (this._inputFile.offsetWidth - 107) + "px";
                    this._inputFile.parentNode.style.width = this._inputFile.offsetWidth + "px";
                }
                if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
                    this._onmouseup$delegate = Function.createDelegate(this, this._onmouseup);
                    $addHandlers(this._inputFile, {
                        mouseup: this._onmouseup$delegate
                    });
                }
            }
        }
    },
    

    http://ajaxcontroltoolkit.codeplex.com/SourceControl/network/Forks/keyoke/AyncFileUploadFix