This is a migrated thread and some comments may be shown as answers.

refresh parent on AJAX postback is working only the first time

14 Answers 479 Views
Window
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 26 Feb 2009, 09:56 PM
Using the suggestions on this forum, I've created a radwindow which refreshes the parent page via AJAX postback.

On the parent page, from code behind, I rebind a control that was updated in the radwindow like this:

protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    {   
        FormView1.DataBind();
    }

FormView1 is an an update panel and it works perfectly the first time.  However, after I reopen the radwindow before a full postback, it does not call the AJAX function again.  I tried setting the radwindow with DestroyOnClose using both true and false and it still doesn't work.

Any suggestions?




14 Answers, 1 is accepted

Sort by
0
Patrick
Top achievements
Rank 1
answered on 27 Feb 2009, 12:17 AM
I also realized that this issue is isolated to Firefox.  Works fine in IE.  Anybody with suggestions?
0
Fiko
Telerik team
answered on 27 Feb 2009, 03:17 PM
Hello Patrick,

I am not quite sure what exactly is your setup. Could you please provide me with more information about the following parts of your project :

  • how do you trigger the AJAX postback.  I saw that you used the RadAjaxManager control, but I need the exact steps of how do you do this. It will be best to provide the exact JavaScript code.
  • I need your RadWindow control setup
  • I need you full RadAjaxManager control setup with all controls that it is configured to update
  • I assume that the FormView is placed in an update panel and I need this code too

For your convenience I suggest you to open a new support ticket and send me a full working project. Then I will rework it and send it back to you.
 
All the best,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Patrick
Top achievements
Rank 1
answered on 27 Feb 2009, 03:31 PM
1. <script type="text/javascript">
        function RadWindowItinerary_Close() {
            alert("new");
            $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest();
                }
    </script>

I also tried the RadAjaxManager1.ClientID

2. <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Behaviors="None"
        Height="430px" Skin="Telerik" Width="700px" >
        <Windows>
            <telerik:RadWindow ID="RadWindowItinerary" runat="server" Behaviors="Close,Move, Resize"
                Modal="True" NavigateUrl="itinerarydialog.aspx"
                OpenerElementID="<%# ButtonItineraryDialogEdit.ClientID %>" Style="display: none;"
                Top="" KeepInScreenBounds="True" Title="Edit Itinerary" VisibleStatusbar="False"
                ReloadOnShow="true" OnClientClose="RadWindowItinerary_Close">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>

3. <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
       
    </telerik:RadAjaxManager>

I left the settings blank.  Whenever I added the Formview1 and RadAjaxManager I started to get strange errors

4. Yes, the formview is an update panel

PS.  It is working in IE and for Firefox it works only the first time.












0
Fiko
Telerik team
answered on 02 Mar 2009, 09:02 AM
Hello Patrick,

I prepared a test project based on the provided code, but I was not able to reproduce the problem. Every time when I pressed the button (that opens the RadWindow)  an AJAX request was triggered and it is working under both browsers - IE and FF.
In this case, it will be best to open a new support ticket and send me a simple demo project that reproduce the problem. Once I have a better view over your exact setup and the problem with it I will be able to provide a solution.

Regards,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mo
Top achievements
Rank 1
answered on 07 Feb 2010, 07:02 PM
hello, was this issue ever resolved?  I'm having the same problem.  When I close the radwindow, which in turn calls the ajax request to rebind a grid on the server side, it works the first time.  But, when i reopen the window and do it again (close the window), the ajax request is not called. I have to reload the page in order to get it working again.  But, it still only works on the first time.  Note: the ajax manager and window are contained in a web usercontrol, if that matters at all.

thanks.
0
Georgi Tunev
Telerik team
answered on 09 Feb 2010, 01:33 PM
Hello Mo,

The scenario that you describe is working fine on our side. Please open a support ticket and send us a sample project so we could check it.

Greetings,
Georgi Tunev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
T. Stanley
Top achievements
Rank 1
answered on 14 Aug 2013, 12:46 AM
Hi.  Did this issue ever get solved per Mo's question?  I ask because thre years later now with all the newest versions of code, IDE, etc., I am having exactly the same problem with the ajax posting occurring only once when using Firefox 22, Chrome 28, or Safari 5.1.  Subsequent attempts to close a window with update does not work, and the window stays open and the underlying grid not updated.  IE 9 works flawlessly every time.  My code:

Contents of RadWindow:
<telerik:RadButton ID="rbtnReturn" runat="server" Text="Return" OnClientClicking="CloseRadWindow">
<Icon PrimaryIconCssClass="rbOk" PrimaryIconLeft="2" PrimaryIconTop="2" />
</telerik:RadButton>
<telerik:RadButton ID="rbtnReturnUpdate" runat="server" Text="Return and update" OnClientClicking="CloseAndRebind">
<Icon PrimaryIconCssClass="rbRefresh" PrimaryIconLeft="2" PrimaryIconTop="2" />
</telerik:RadButton>

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow)
        oWindow = window.radWindow;
    else if (window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
    return oWindow;
}
function CloseRadWindow() {
    GetRadWindow().close();
}
function CloseAndRebind() {
    GetRadWindow().BrowserWindow.refreshGrid(); // refreshGrid is defined on calling page
    CloseRadWindow();
}


And in the calling page with the RadGrid:
function refreshGrid() {
        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();
}

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
        scheduleRadGrid.Rebind();
}

Again, it works great in IE, but not in any other browser.  Please advise.

Many thanks!

Tom Stanley


0
Marin Bratanov
Telerik team
answered on 14 Aug 2013, 10:45 AM
Hi Tom,

This is also a peculiar report and I am not aware of reasons for such behavior. Can you confirm there are no JavaScript errors on the page? What I can suggest in the meantime is the following:
- use the generic __doPostBack() function to initiate a request. You can use regular update panels and the UniqueID of a button in them that is hidden with CSS to get an easy server event
- try adding a small timeout around the ajaxRequest() call
- if you have the AjaxControlToolkit in the project, try removing it (delete the dll) to see if it helps. It changes some of the MS AJAX scripts and may break event handlers
- if neither helps I would, once again, advise on sending us a sample we can run and inspect, because such a problem would stem from something specific in the project

In the case with Mo's issue there were user controls that were dynamically created and this had to happen early enough in the page lifecycle (usually the Page_Init is the proper event, but on that case PreInit seems to have resolved the case). Also, getting a refernce to the RadAjaxManager that is on the main page from a user control is done like this: $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest();


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sam
Top achievements
Rank 1
answered on 12 Dec 2013, 09:59 PM
Anyone have solution for this yet?

In IE, there is no error in console, but in Firefox or Chrome there is error in console

1. First time after click submit button from RadWindow.  RadWindow will close and refresh the parent page
Uncaught SyntaxError: An invalid or illegal string was specified. Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:1578

2.  Launch RadWindow for second time, click submit button from RadWindow again.  RadWindow will NOT close.
Uncaught TypeError: Cannot call method 'ajaxRequest' of null

And if you keep clicking the submit button from RadWindow, it continues with error Cannot call method 'ajaxRequest' of null

The submit button does postback every time it is clicked.

I search for solution in Window forum, but I could not find a solution. Please help!

Thanks,
Sam
0
Marin Bratanov
Telerik team
answered on 13 Dec 2013, 11:24 AM
Hi Sam,

We have never actually received a sample that show this behavior and we cannot say what the reason might be. Thus, the suggestions from my previous answer are still valid: http://www.telerik.com/community/forums/aspnet-ajax/window/refresh-parent-on-ajax-postback-is-working-only-the-first-time.aspx#2746832.


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sam
Top achievements
Rank 1
answered on 13 Dec 2013, 01:18 PM
Hello,

This is sample that shows the behavior.

I have 2 web page Main.aspx and EditForm.aspx.  This sample very similar to demo http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window

On main.aspx page, it has:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" ></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="gridLoadingPanel"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
      </AjaxSettings>
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel runat="server" ID="gridLoadingPanel"></telerik:RadAjaxLoadingPanel>
 
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel2" LoadingPanelID="gridLoadingPanel">
 A RADGRID GOES HERE
 
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" Behaviors="Close,Resize,Reload,Move,Maximize" EnableViewState="false">
                        <Windows>
                            <telerik:RadWindow ID="UserListDialog" runat="server" Title="Add New Record" Width="1024px" Height="320px"
                                MinWidth="320px" MinHeight="250px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"
                                Modal="true">
                            </telerik:RadWindow>
                        </Windows>
                    </telerik:RadWindowManager>
</telerik:RadAjaxPanel>
 
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
                <script type="text/javascript">
                    function ShowEditForm(id, rid, vid, rowIndex) {
                        var grid = $find("<%= RadGrid1.ClientID %>");
 
                        var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
                        grid.get_masterTableView().selectItem(rowControl, true);
 
                        window.radopen("EditForm.aspx?id=" + id + "&vid=" + vid + "&rid=" + rid, "UserListDialog").maximize();
                        return false;
                    }
                    function ShowInsertForm(id, vid) {
                        var oWnd = radopen("EditForm.aspx?id=" + id + "&vid=" + vid, "UserListDialog");
                        oWnd.maximize();
                        return false;
                    }
                    function refreshGrid(arg) {
                        if (!arg) {
                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                        }
                        else {
                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                        }
                    }
                    function RowDblClick(sender, eventArgs) {
                        window.radopen("EditFormcs.aspx?EmployeeID=" + eventArgs.getDataKeyValue("EmployeeID"), "UserListDialog");
                    }
                </script>
            </telerik:RadCodeBlock>

Main.aspx code behind:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                if (e.Item.OwnerTableView.Name == "Parent")
                {
                    Button editLink = (Button)e.Item.FindControl("EditLink");
                    editLink.Attributes["href"] = "javascript:void(0);";
                    editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}','{2}','{3}');",
                        e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EID"],
                        e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["RID"],
                        e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["VID"],
                        e.Item.ItemIndex);
                }
                else if (e.Item.OwnerTableView.Name == "Child")
                {
                    // nothing
                }
            }
            if (e.Item is GridCommandItem)
            {
                GridCommandItem cmditem = (GridCommandItem)e.Item;
                Button addLink = (Button)cmditem.FindControl("AddNewRecordLink");
                addLink.Attributes["href"] = "javascript:void(0);";
                addLink.Attributes["onclick"] = String.Format("return ShowInsertForm('{0}','{1}');",
                   txtEID.Text,
                   hfVID.Value);
            }
}

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "Rebind")
            {
                RadGrid1.MasterTableView.SortExpressions.Clear();
                RadGrid1.MasterTableView.GroupByExpressions.Clear();
                RadGrid1.Rebind();
            }
            else if (e.Argument == "RebindAndNavigate")
            {
                RadGrid1.MasterTableView.SortExpressions.Clear();
                RadGrid1.MasterTableView.GroupByExpressions.Clear();
                RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1;
                RadGrid1.Rebind();
            }
        }

On Editform.aspx (This page is different from the demo link above) I use RadTextBox and RadButton instead DetailsView .NET control
<telerik:RadScriptBlock runat="server">
            <script type="text/javascript">
                function pageLoad() {
 
                }               
                function get(button, args) {
                    var id = $get("rdpDate").value;
                    alert(id);
                }
                function CloseAndRebind(args) {                   
                    GetRadWindow().BrowserWindow.refreshGrid(args);
                    GetRadWindow().close();                   
                }
                function CancelEdit() {
                    GetRadWindow().close();
                }
                function GetRadWindow() {
                    var oWindow = null;
                    if (window.radWindow) oWindow = window.radWindow;
                        //Will work in Moz in all cases, including clasic dialog  
                    else if (window.frameElement.radWindow)
                        oWindow = window.frameElement.radWindow;
                    //IE (and Moz as well)             
                    return oWindow;
                }
</script>
        </telerik:RadScriptBlock>

Editform.aspx code behind
protected void rbSubmit_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
        }

Thanks,
Sam
0
Marin Bratanov
Telerik team
answered on 17 Dec 2013, 09:03 AM
Hello Sam,

This works fine for me. You can find attached the pages I built for testing and a video from my experiment as a reference.

What I can suggest at this point is:
- try the latest version of the controls
- try adding timeouts, or any of the other workarounds I previously suggested
- try adding a timeout around the close() call of the RadWindow in the edit form. You can also try using the OnClientClose event of the RadWindow and pass arguments to the close() method. You can see how to do this here.


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sam
Top achievements
Rank 1
answered on 19 Dec 2013, 08:35 PM
Hi Marin,

I tried your sample on my side. It is working fine.  But when looking your sample to compare with my project pretty much identical, except I used Master Page for the Main.aspx

and I'm still getting the issue.

I have no clue what to go next.  Please help.

Thanks,
Sam
0
Sam
Top achievements
Rank 1
answered on 19 Dec 2013, 10:25 PM
Never mind, I found the problem.

The problem is inside <style></style> tag of the Main page

I commented out my css style like this
/* input.riTextBox { border-color: black !important; } */



some javascripts looking for the { (curly bracket), I don't what javascript cause this (because I have telerik, bootstrap, or jquery in my project)

but when I clear /* input.riTextBox { border-color: black !important; } */ error gone away.

Thank you so much for your help
-Sam
Tags
Window
Asked by
Patrick
Top achievements
Rank 1
Answers by
Patrick
Top achievements
Rank 1
Fiko
Telerik team
Mo
Top achievements
Rank 1
Georgi Tunev
Telerik team
T. Stanley
Top achievements
Rank 1
Marin Bratanov
Telerik team
Sam
Top achievements
Rank 1
Share this question
or