代码之家  ›  专栏  ›  技术社区  ›  Rohan West

使用ASP.NET刷新不带更新程序面板的控件。NET AJAX

  •  1
  • Rohan West  · 技术社区  · 17 年前

    这个问题与我之前的问题直接相关 ASP.NET AJAX

    是否可以异步执行回发?我在页面上有多个CustomTextbox控件,当我回发时,我想更新表单上的另一个控件。

    如果我在第一次发布后将所有控件放在更新器面板中,回到一个需要几秒钟才能完成的过程中,那么我对用原始值渲染的其他控件所做的任何更改。

    你知道怎么解决这个问题吗?

    Type.registerNamespace('Demo');
    
    Demo.CustomTextBox = function(element) {
        Demo.CustomTextBox.initializeBase(this, [element]);
    }
    
    Demo.CustomTextBox.prototype = {
    
        initialize: function() {
            Demo.CustomTextBox.callBaseMethod(this, 'initialize');
    
            this._onblurHandler = Function.createDelegate(this, this._onBlur);
    
            $addHandlers(this.get_element(),
                         {
                             'blur': this._onBlur
                         },
                         this);
        },
    
        dispose: function() {
            $clearHandlers(this.get_element());
    
            Demo.CustomTextBox.callBaseMethod(this, 'dispose');
        },
    
        _onBlur: function(e) {
        if (this.get_element() && !this.get_element().disabled) {
                /* Cridit to AdamB for this line of code */
                __doPostBack(this.get_element().id, 0);
            }
        }
    }
    
    Demo.CustomTextBox.registerClass('Demo.CustomTextBox', Sys.UI.Control);
    
    if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
    
    1 回复  |  直到 17 年前
        1
  •  2
  •   Robert Wagner    17 年前

    仅将更新面板放在需要更新的控件周围,并使触发更改的控件在该更新面板上触发:

    <asp:TextBox runat="server" ID="Entry2" />
    <asp:TextBox runat="server" ID="Entry1" />
    <asp:UpdatePanel>
        <ContentTemplate>
            <asp:TextBox runat="server" ID="Result" ReadOnly="true" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Entry1" />
            <asp:AsyncPostBackTrigger ControlID="Entry2" />
        </Triggers>
    </asp:UpdatePanel>
    

    因此,当回发完成时,只有更新面板内的内容会发生变化。AJAX返回页面上所有控件的值,而不仅仅是内容模板中的值。

    选项2(涉及更多)是编写一个执行计算的web服务和一些javascript来调用它。