找不到AjaxManager ... null

时间:2012-04-26 13:34:24

标签: javascript jquery asp.net telerik

我有User ControlContent Page。在Content Page中,我在RadDockLayout controlUpdate panel如下所示。我有一个Image button,一旦用户将RadDock的位置换成Drag Drop。用户按下保存按钮将订单保存在数据库中。

<asp:updatepanel id="UpdatePanel1" runat="server">
    <ContentTemplate>
        <telerik:RadDockLayout runat="server" OnLoadDockLayout="RadDockLayout1_LoadDockLayout"
            ID="RadDockLayout1" OnSaveDockLayout="RadDockLayout1_SaveDockLayout">

                        <telerik:RadDockZone runat="server" Orientation="Horizontal" ID="HealthZone" Visible="false"
                            BorderStyle="None" Style="margin: 0;">
                        </telerik:RadDockZone>
                        <telerik:RadDockZone runat="server" Orientation="Horizontal" ID="RadDockZone1" BorderStyle="None"
                            Style="margin: 0; width:540px;">
                        </telerik:RadDockZone>
                        <telerik:RadDockZone runat="server" Orientation="Horizontal" ID="AdZone" Visible="false"
                            BorderStyle="None" Style="margin: 0;" Width="324px">
                        </telerik:RadDockZone>

        </telerik:RadDockLayout>

    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="imgsave" EventName="Click" />
    </Triggers>
</asp:updatepanel>

在保存过程中,我调用另一个函数。这也在User Control下。

public void RePopulateOverview(UserControl overviewuc)
{
    RePopulated = true;
    CurrentDockStates.Clear();
    RadAjaxManager AjaxManager = RadAjaxManager.GetCurrent(this.Page);
    AjaxManager.AjaxSettings.Clear();
    AjaxManager.AjaxSettings.AddAjaxSetting(AjaxManager, overviewuc);
    //InitiateAjaxRequest
    RadScriptManager.RegisterStartupScript(this.UpdatePanel1, 
    this.GetType(), "OverviewReLoadScript" + 
    Guid.NewGuid().ToString().Replace("-", "a"), 
    "javascript:InitiateAjaxRequest();", true);
}

及以下是相应的javaScript函数,如下所示。

<script type="text/javascript">
    function InitiateAjaxRequest() {
        if ($find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>") != null)
            $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>").ajaxRequest();
        else {
            alert("AjaxManager not found..." + $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>"));
        }
    } 
</script>

我的问题是当presses Save Button second time crashesError Message低于此时。

找不到AjaxManager ... null

2 个答案:

答案 0 :(得分:0)

尝试将其作为解决方法:

<script type="text/javascript">
    var ajaxMgrInstance = null;
    function InitiateAjaxRequest() {
        if (ajaxMgrInstance == null) {
            ajaxMgrInstance == $find("<%= myRadAjaxManager.ClientID %>");
        }
        if (ajaxMgrInstance != null) {
            ajaxMgrInstance.ajaxRequest();
        }
        else {
            alert("AjaxManager not found..." + "<%= myRadAjaxManager.ClientID %>");
        }
    } 
</script>

与此同时,我会尝试更好地找出问题的根本原因。

编辑:更新了$find调用,以匹配Telerik API文档的语法。

答案 1 :(得分:0)

应该是这样的。

var ID;
function InitiateAjaxRequest() {
    if (ID == null) {
        ID = $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>");
        ID.ajaxRequest();
    }
    else
        ID.ajaxRequest();
}