Monday, December 8, 2014

How to refresh parent page on closing of Pop Up Window, RadGrid

In this, I will show you how to can refresh a RadGrid control on the parent page, from a pop up window when it is closed.

Main Page.aspx
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" nablePageHeadUpdate="False" EnableAJAX="true">
</telerik:RadAjaxManager>

function ShowInsertForm()
{
var manager = window.radopen("PopUp.aspx", "PopUp");
manager.setSize(650, 325);
manager.set_visibleStatusbar(false);
manager.center();
manager.SetActive();
return false;
}

function RefreshGrid(arg)
{
 if (!arg)
 {
  var AjaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
  if (AjaxManager != null)
  AjaxManager.ajaxRequest("Rebind");
 }
else
 {
  var AjaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
  if (AjaxManager != null)
  AjaxManager.ajaxRequest("RebindAndNavigate");
 }
}

<telerik:RadWindowManager ID="RadWindowManager2" runat="server" EnableShadow="false" OnClientPageLoad="OnClientPageLoad" VisibleStatusbar="false">
        <Windows>
            <telerik:RadWindow ID="PopUp" runat="server" Title="Popup window" ReloadOnShow="true" Behaviors="Maximize,Close,Minimize,Move,Pin" ShowContentDuringLoad="false" Modal="true">
            </telerik:RadWindow>
        </Windows>

    </telerik:RadWindowManager>
MainPage.aspx.cs

  //Register the AjaxManager here
protected void Page_Load(object sender, EventArgs e)
{
  RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
  manager.AjaxRequest += new     RadAjaxControl.AjaxRequestDelegate(RadAjaxManager1_AjaxRequest);
}

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
 if (e.Argument == " CloseAndRebind ")
 {
  // Refresh /Reload the grid control here
 }
}
Popup.aspx
<telerik:RadScriptManager ID="RadScriptManagerPopUp" runat="server" ></telerik:RadScriptManager>
      <script type="text/javascript">
          function CloseAndRebind(args) {
              GetRadWindow().BrowserWindow.refreshGrid(args);
              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;
          }
          function CancelEdit() {
              GetRadWindow().close();
          }

    </script>
Popup.aspx.cs

private void Close()
{
 ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
}



No comments:

Post a Comment