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

Issue with refresh parent grid from radwindow

2 Answers 24 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
nav100
Top achievements
Rank 1
nav100 asked on 16 Sep 2013, 10:45 PM
I am trying to refresh parent grid from radwindow. Here is my code. Radiwindow opens but it doesn't close and also doesn't refresh. I am not using RadAjaxManager because RadAjaxManager is on the Master page. Please let me know what am I doing wrong?

Parent Page Code:
----------------------------------------
<script type="text/javascript">
    function refreshGrid() {
        var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
        masterTable.rebind();  
    }
</script>

<telerik:RadWindowManager runat="server" ID="RadWindowManager1" OnClientClose="refreshGrid" />
  <telerik:RadGrid ID="RadGrid1"
                           runat="server"
                GridLines="None" Skin="Default" OnNeedDataSource="RadGrid1_NeedDataSource"
                 OnItemCommand="RadGrid1_ItemCommand"   >
 <MasterTableView DataKeyNames="id" PageSize="50" EditMode="EditForms">
<Columns>
<telerik:GridButtonColumn Text="View/Edit" UniqueName="EditColumn" CommandName="EditLink"></telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

.aspx.cs code
----------------------------
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            long ID = Convert.ToInt64((e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["item_id"]));
            if (e.CommandName == "EditLink")
            {
                RadWindow win = new RadWindow();
                win.ID = "window1";
                win.VisibleOnPageLoad = true;
                win.NavigateUrl = "Page1.aspx?ID=" + ID.ToString();
                RadWindowManager1.Controls.Add(win);
            }
        }

Radwindow page:(Child Window)
----------------------------------------------
<script type="text/javascript">
    function CloseAndRebind() {
        var oWin = GetRadWindow();
        var parentWindow = oWin.BrowserWindow;
        $(oWin).ready(function () {
            oWin.close();
        });
        parentWindow.refreshGrid();
    }

    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including classic dialog
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)

        return oWindow;
    }
</script>

.aspx page
---------------
<asp:Button ID="Save" Text="Save" runat="server" OnClick="save_Click" />

Code behind
----------------------------
        protected void save_Click(object sender, EventArgs e)
        {
            try
            {
            save();

                //Close Pop up
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "mykey", "CloseAndRebind();", true);
             
            }



   

2 Answers, 1 is accepted

Sort by
0
nav100
Top achievements
Rank 1
answered on 17 Sep 2013, 08:16 PM
telerik experts, Could you please help? I was able to open the RadWindow and submit the page. Now I would like to refresh only the parent grid after the window closes.  I see on your site the demo with AjaxManager on the page. But I am not sure how to use AjaxManager in my case because it is already exists in master page.
0
Konstantin Dikov
Telerik team
answered on 19 Sep 2013, 03:16 PM
Hi Nara,

I am glad to see that you were able to find solution for some of the issues. 

Now for you current question, regarding the Master/Content page scenario: in a complex scenario like WebUserControls or Master/ContentPages you should use RadAjaxManager in the Master page and RadAjaxManagerProxy in the Content page. Please refer to the following help article: "RadAjaxManagerProxy".

Furthermore for your scenario I may suggest that you fire an AJAX request within the "refreshGrid" function with RadGrid as initiator (the RadGrid must be set as AJAX initiator and as "UpdatedControl" in the RadAjaxManagerProxy as well). More information could be found at this help article.

Another important thing that should be pointed out is that you need to move the following line from the "ItemCommand" server-side event to the "Page_Load" event in order to overcome ViewState errors that will occur:
win = new RadWindow();
RadWindowManager1.Controls.Add(win);
win.ID = "window1";


Hope that helps.

 

Regards,
Konstantin Dikov
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.
Tags
Ajax
Asked by
nav100
Top achievements
Rank 1
Answers by
nav100
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or