prevent完全回发从__doPostBack [英] Prevent Full Postback from __doPostBack

查看:218
本文介绍了prevent完全回发从__doPostBack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下......

内容页

  

      
  1. UpdatePanel1 - 包含错误显示的div

        包含UPDATE触发器的两个按钮

  2.   
  3. UpdatePanel2 - 包含流程1一个asp:按钮

  4.   
  5. updatePanel3 - 包含过程2一个asp:按钮

  6.   
  7. 的JavaScript presents一个弹出用户确认jQuery的消息框基础上,他们正在执行过程中。

  8.   

根据从菜单选项中的用户选择的UpdatePanel 2或3变得可见。

当我点击消息框持久性有机污染物,并在页面处理正确使用__doPostBack从消息框响应按钮,页面做了完全回发。

我宁愿做第一个部分回发,它有内容,如果有一个错误显示错误显示的div。任何援助将AP preciated。

没有什么特别的按钮

 < ASP:按钮的ID =ResetSomething=服务器文本=ResetSomethingWIDTH =275px/>

下面是内容页脚本块

 <脚本类型=文/ JavaScript的LANGUAGE =JavaScript的>
<! -
    功能页面加载(){
        setform();    };    功能setform(){
        VAR reset1_button = $('输入[ID * = ResetSomething]');
        VAR reset2_button = $('输入[ID * = ResetSomethingElse]');        reset1_button.click(函数(){
            VAR元= $(本);
            $ .prompt('消息1',{显示:'了slideDown',纽扣:【OK:真,取消:假},
                提交:功能(V,M,F){submit_reset_callback(V,M,元素); }
            });
            返回(假);
        });        VAR submit_reset_callback =功能(结果,消息元素){
            如果(结果){__do​​PostBack(ResetSomething);}
            返回(假);
        };        reset2_button.click(函数(){
            VAR元= $(本);
            $ .prompt('消息2',{显示:'了slideDown',纽扣:【OK:真,取消:假},
                提交:功能(V,M,F){submit_update_callback(V,M,元素); }
            });
            返回(假);
        });        VAR submit_update_callback =功能(结果,消息元素){
            如果(结果){__do​​PostBack(ResetSomethingElse); }
            返回(假);
        };
    };
- >
< / SCRIPT>

这是背后的OnInit中的code:

 保护覆盖无效的OnInit(EventArgs的发送)
    {
        base.OnInit(E);
        这preLOAD + =(发件人,参数)=>
                            {                                this.ClientScript.GetPostBackEventReference(这一点,ARG);                                (!的IsPostBack){如果返回; }                                字符串__targetaction = this.Request [__ EVENTTARGET];
                                字符串__args = this.Request [__ EVENTARGUMENT];                                如果(string.IsNullOrEmpty(__参数))回报;                                如果(__targetaction ==ResetSomething)
                                {
                                    ResetSomething();
                                }
                                如果(__targetaction ==ResetSomethingElse)
                                {
                                    ResetSomethingElse();
                                }
                                this.upnlNotifications.Update();
                            };
    }


解决方案

定义下面的功能,并取代你的 __ doPostBack 调用doPostBackAsync(控件, NULL)

 函数doPostBackAsync(eventName的,EventArgs的){
    变种PRM = Sys.WebForms.PageRequestManager.getInstance();    如果(!Array.contains(prm._asyncPostBackControlIDs,eventName的)){
        prm._asyncPostBackControlIDs.push(eventName的);
    }    如果(!Array.contains(prm._asyncPostBackControlClientIDs,eventName的)){
        prm._asyncPostBackControlClientIDs.push(eventName的);
    }    __doPostBack(eventName的,EventArgs的);
}

I have a content page that contains the following...

  1. UpdatePanel1 - containing Error Display Divs
    contains update triggers for both buttons
  2. UpdatePanel2 - containing process 1 with an asp:button
  3. updatePanel3 - containing process 2 with an asp:button
  4. JavaScript that presents the user with a Popup confirm Jquery Messagebox based on the process they are executing.

UpdatePanel 2 or 3 becomes visible based on the users selection from the menu options.

When I click a button the messagebox pops and the page is processed correctly using __doPostback from the messagebox response and the page does a full postback.

I would rather the page do a partial postback and the content it had and display the Error Display Divs if there was an error. Any assistance would be appreciated.

nothing special about the button

<asp:Button ID="ResetSomething" runat="server" Text="ResetSomething" Width="275px" />

here is the content page script block

    <script type="text/javascript" language="javascript">
<!--
    function pageLoad() {
        setform();

    };

    function setform() {
        var reset1_button = $('input[id*=ResetSomething]');
        var reset2_button = $('input[id*=ResetSomethingElse]');

        reset1_button.click(function() {
            var element = $(this);
            $.prompt('Message1', { show: 'slideDown', buttons: { Ok: true, Cancel: false },
                submit: function(v, m, f) { submit_reset_callback(v, m, element); }
            });
            return (false);
        });

        var submit_reset_callback = function(result, messages, element) {
            if (result) { __doPostBack("ResetSomething");}
            return (false);
        };

        reset2_button.click(function() {
            var element = $(this);
            $.prompt('Message2', { show: 'slideDown', buttons: { Ok: true, Cancel: false },
                submit: function(v, m, f) { submit_update_callback(v, m, element); }
            });
            return (false);
        });

        var submit_update_callback = function(result, messages, element) {
            if (result) { __doPostBack("ResetSomethingElse"); }
            return (false);
        };
    };     
-->
</script>

this is the code behind for the OnInit:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.PreLoad += (sender, args) =>
                            {

                                this.ClientScript.GetPostBackEventReference(this, "arg");

                                if (!IsPostBack) { return; }

                                string __targetaction = this.Request["__EVENTTARGET"];
                                string __args = this.Request["__EVENTARGUMENT"];

                                if (string.IsNullOrEmpty(__args)) return;

                                if (__targetaction == "ResetSomething")
                                {
                                    ResetSomething();
                                }
                                if (__targetaction == "ResetSomethingElse")
                                {
                                    ResetSomethingElse();
                                }
                                this.upnlNotifications.Update();
                            };
    }

解决方案

Define the function below and replace your __doPostBack calls with doPostBackAsync(controlId, null).

function doPostBackAsync(eventName, eventArgs) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
        prm._asyncPostBackControlIDs.push(eventName);
    }

    if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }

    __doPostBack(eventName, eventArgs);
}

这篇关于prevent完全回发从__doPostBack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆