异步回发不工作 [英] Async postback not working

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

问题描述

我用我的ContentPlaceHolder此计。

I'm using this gauge in my contentplaceholder.

http://www.dariancabot.com/projects/jgauge_wip/

MyControl.ascx:

MyControl.ascx:

<link rel="stylesheet" href="Scripts/jgauge.css" type="text/css" />
<script type="text/javascript" src="Scripts/jquery-1.8.0.js"></script>
<script language="javascript" type="text/javascript" src="Scripts/jgauge-0.3.0.a3.js"></script>
<script language="javascript" type="text/javascript" src="Scripts/jQueryRotate.2.2.js"></script>
<script language="javascript" type="text/javascript" src="Scripts/excanvas.min.js"></script>

<div id="<%=this.ClientID%>_ctl" class="jgauge" ></div>

<script type="text/javascript">
    $(document).ready(function () {
    var isPostBack = <%= Page.IsPostBack ? "true" : "false" %>;
        if(isPostBack == "true")
        {
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
            prm.add_endRequest(onEndRequest);
        }
        else{
                var <%=this.ClientID%>_ctl;

                <%=this.ClientID%>_ctl = new jGauge(); 
                <%=this.ClientID%>_ctl.id = '<%=this.ClientID%>_ctl';
                <%=this.ClientID%>_ctl.init(); 
 }
    });

    function EndRequestHandler(sender, args){  
        var <%=this.ClientID%>_ctl;
        <%=this.ClientID%>_ctl = new jGauge(); 
        <%=this.ClientID%>_ctl.id = '<%=this.ClientID%>_ctl';
        <%=this.ClientID%>_ctl.init();
}
</script>

在MyPage.aspx:(包含有几个这样的控制将所生成的表占位符动态创建的表)

In MyPage.aspx: (Contains dynamically created table having several such controls. putting the generated table on placeholder)

<asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
        <asp:PlaceHolder id="phMain" runat="server" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="myBtn" />
    </Triggers>
</asp:UpdatePanel>
<asp:Button ID="myBtn" runat="server" Text="Refresh" /> 

我有剧本经理母版页上:

I have script manager on master page:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>

但异步回发后(打'myBtn'),表中消失。请帮忙。试图解决它,因为几天。

But after async postback (hitting 'myBtn'), gauge disappears. Please Help. Trying to solve it since couple of days.

推荐答案

我能够通过去一起解决这个问题:

I was able to solve this with by going:

$(document).ready(function () { 
    Sys.WebForms.PageRequestManager.getInstance()
        .add_endRequest(<%=this.ClientID%>_ctlEndRequestHandler); 
    var <%=this.ClientID%>_ctl; 

    <%=this.ClientID%>_ctl = new jGauge();  
    <%=this.ClientID%>_ctl.id = '<%=this.ClientID%>_ctl'; 
    <%=this.ClientID%>_ctl.init();
});

function <%=this.ClientID%>_ctlEndRequestHandler(sender, args){
    var <%=this.ClientID%>_ctl; 
    <%=this.ClientID%>_ctl = new jGauge();  
    <%=this.ClientID%>_ctl.id = '<%=this.ClientID%>_ctl'; 
    <%=this.ClientID%>_ctl.init(); 
}

唯一的区别是,回发检查不再发生。你的根本问题是 $(文件)。就绪将不会触发对部分回发,这意味着的IsPostBack 从不实际上越来越设置为true。正因为如此, Sys.WebForms.PageRequestManager.getInstance()add_endRequest(EndRequestHandler); 从来没有执行,这意味着你的 EndRequestHandler 绝然。

The only real difference is that the postback checks are no longer taking place. Your underlying problem is that $(document).ready will not fire on partial postbacks, which means that isPostBack is never actually getting set to true. Because of this, Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); was never executing, meaning that your EndRequestHandler never ran.

修改

另一个问题是,命名方法 EndRequestHandler 保证,如果你有在同一时间控制多个引起问题。为了解决这个问题,我追加&LT;%= this.ClientID%GT; _ctl EndRequestHandler 的名称确保是独一无二的。

The other issue is that naming the method EndRequestHandler is guaranteed to cause problems if you have more than one of the control at the same time. To get around this, I appended <%=this.ClientID%>_ctl to the name of EndRequestHandler to ensure it was unique.

更多信息:

<一个href=\"http://stackoverflow.com/questions/1750368/how-do-i-use-a-jquery-document-ready-and-an-asp-net-updatepanel-together?rq=1\">How我用一个jQuery的$(document)。就绪和一个ASP.NET的UpdatePanel在一起吗?

http://encosia.com/document-ready -and-页面加载 - 是 - 不是最相同/

这篇关于异步回发不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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