0

I have a User Control and a Content Page. In the Content Page, I have a RadDockLayout control inside Update panel like below. I have an Image button, Once user swaps the position of RadDock by Drag Drop. User presses save button to save the order in database.

<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>

During the save process, I call another function. which is also under 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);
}

and below is the corresponding javaScript Function like below.

<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>

My Issue is When I presses Save Button second time it crashes and Error Message is below.

AjaxManager not found...null

Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • Sorry, haven't figured out what's going on here. For anyone else wanting to take a crack at it, you can [see the client API for RadAjaxManager here](http://www.telerik.com/help/aspnet-ajax/ajax-client-side-api.html). – Mike Guthrie Apr 26 '12 at 19:23

2 Answers2

0

Try this as a work-around:

<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>

Meanwhile I'll try to better locate the root cause of the issue.

EDIT: Updated $find call to match syntax of Telerik's API documentation.

Mike Guthrie
  • 4,029
  • 2
  • 25
  • 48
  • It is always going inside the else statement actually. – Pankaj Apr 27 '12 at 08:49
  • @Guest Try my solution, now. I updated the `$find` call to use the `ID` property (assuming `myRadAjaxManager`) instead of using the `GetCurrent` call. This is how Telerik has it in their documentation (my link in my comment to your question). – Mike Guthrie Apr 27 '12 at 11:14
  • I don't have the control explicitly in the form. That's the reason I am using it that way. Thanks a lot for the hint. – Pankaj Apr 27 '12 at 18:07
  • @Guest Was afraid that might be the case. And couldn't tell you what difference it would make anyway (shouldn't, but figured it worth a shot). – Mike Guthrie Apr 27 '12 at 18:35
0

It should be like this.

var ID;
function InitiateAjaxRequest() {
    if (ID == null) {
        ID = $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>");
        ID.ajaxRequest();
    }
    else
        ID.ajaxRequest();
}
Pankaj
  • 9,749
  • 32
  • 139
  • 283