【问题标题】:Refresh Control without Updater Panel using ASP.NET AJAX使用 ASP.NET AJAX 在没有更新程序面板的情况下刷新控件
【发布时间】:2008-11-19 03:51:14
【问题描述】:

这个问题和我之前的问题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();

【问题讨论】:

    标签: asp.net ajax


    【解决方案1】:

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

    <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 来调用它。

    【讨论】:

    • 干杯罗伯特,我想可能是这样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    相关资源
    最近更新 更多