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

Parent Grid Bind after Update

11 Answers 312 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 11 Jul 2008, 08:58 PM
I use a RadWindow to update a row in my grid.  In the RadWindow I click save and have an event to handle the transaction.  However, the window closes but the parent page with the grid does not rebind/refresh with the new data. 

How do you get it to refresh on a save from a RadWindow?

All I have so far is to close the window.
string closingScript;  
closingScript = "<script type='text/javascript'>window.onload = closeWin</script> ";  
ClientScript.RegisterStartupScript(this.GetType(), "closeWin", closingScript); 

11 Answers, 1 is accepted

Sort by
0
Shaun Peet
Top achievements
Rank 2
answered on 14 Jul 2008, 12:49 AM
The easiest way is to execute a script on the grid's page from within the window's page.  This is the way that I usually do it:

On the window's page have:

function get_RadWindow() {   
  var oWindow = null;   
  if (window.radWindow) { oWindow = window.radWindow; }   
  else if (window.frameElement.radWindow) { oWindow = window.frameElement.radWindow; }   
  return oWindow;   
}  
 
function CloseAndRebind() {   
  get_RadWindow().BrowserWindow.postBackHF();   
  get_RadWindow().Close();   
}     
 

The CloseAndRebind function calls get_RadWindow to get the RadWindow's client object and calls it's BrowserWindow object to get the calling (parent) page object, and then calls a function (postBackHF) on that page.

On the grid's page place an <asp:hiddenfield /> somewhere on the page (inside an updatepanel if you want to refresh with ajax), and have this:

var HFID = "<%= HiddenField1.ClientID %>";  
function postBackHF() { var hF = $get(HFID); if (hF) { hF.value = (new Date()).getTime(); __doPostBack(HFID, ''); } }  
 

This will force the hidden field to postback with a new value, so in your server-side code setup your code to handle the hidden field's ValueChanged event so that it refreshes the grid.

I've got a couple other enhancements if you want, but that should get you started.

0
Mike
Top achievements
Rank 1
answered on 20 Jul 2008, 09:24 PM
Thanks, but I tought Telerik would have a built in solution.  What other enhancements do you have?

Thank You!
0
Shaun Peet
Top achievements
Rank 2
answered on 20 Jul 2008, 09:47 PM
Well, you may already be doing this, but on the window's page I would suggest adding a RadAjaxManager, and then add whatever Button (or LinkButton, or FormView) you use to update the form to the collection of ajaxified controls.  To execute the client script after the button's postback, use

RadAjaxManager1.ResponseScripts.Add("CloseAndRebind()")

This will eliminate any screen flicker in the window's page and also tends to make it work just a little faster.

On the parent page, simply put the RadGrid and the HiddenField inside a good 'ole asp:UpdatePanel and the refreshing becomes ajaxified.

This may be a bit of a philosophical thing, but if you're not using the RadGrid for any of its other features, such as grouping, sorting, filtering, paging, etc. then you'd be better off using either a Repeater or a ListView control as that will speed things up too (sorry, Telerik).

Now, in response to your comment about Telerik having this built-in.  They do, sort of.  There is a "Pop-Up Edit Form" mode for the Grid (which I think now uses a Dock control instead of a Window) which does automatically rebind the grid after an update.  Demo is here:

http://www.telerik.com/demos/aspnet/prometheus/Grid/Examples/DataEditing/PopUpEditForm/DefaultCS.aspx

I have found in my own experience, though, that it's far easier to make the data entry form look good and easy to use by creating my own .aspx page and opening it in a window as you are already doing.  But in terms of what is the easiest possible solution for the developer, what Telerik has built-in is the best.


Hope that helps,

Shaun.
0
Mike
Top achievements
Rank 1
answered on 21 Jul 2008, 06:29 PM
I am not a fan of the Telerik way either.  I like to have more control with my forms.

It is working with the cancel button but not the save.

RadWindow page
   <script type="text/javascript">    
        function get_RadWindow()   
        {      
          var oWindow = null;      
          if (window.radWindow)   
          {   
          oWindow = window.radWindow;   
          }      
          else if (window.frameElement.radWindow)   
          {  
           oWindow = window.frameElement.radWindow;   
           }      
          return oWindow;      
        }                 
        function CloseAndRebind()   
        {      
          get_RadWindow().BrowserWindow.postBackHF();      
          get_RadWindow().Close();      
        }       
    </script> 


<asp:Button ID="ButtonSave" Text="Save" OnClick="ButtonSave_Click" CausesValidation="true" Width="100px" runat="server" ValidationGroup="validationSummaryComments" /> 
<asp:Button ID="ButtonCloseHide" Text="Cancel" Width="50px" CausesValidation="false" OnClientClick="CloseAndRebind();" runat="server" />    

Code Behind on RadWindow Save.
  protected void ButtonSave_Click(Object obj, EventArgs e)  
    {  
        if (Page.IsValid)  
        {  
          // Do some work  
        }  
        string closingScript;  
        closingScript = "<script type='text/javascript'>window.onload = CloseAndRebind</script> ";  
        ClientScript.RegisterStartupScript(this.GetType(), "CloseAndRebind", closingScript);  
    } 
0
Shaun Peet
Top achievements
Rank 2
answered on 21 Jul 2008, 06:40 PM
I don't have anything small ready to go, but if you can give me a couple of days I can get something up here for you.
0
Shaun Peet
Top achievements
Rank 2
answered on 23 Jul 2008, 04:57 AM
I don't think you need all this:

        string closingScript;  
        closingScript = "<script type='text/javascript'>window.onload = CloseAndRebind</script> ";  
        ClientScript.RegisterStartupScript(this.GetType(), "CloseAndRebind", closingScript);  


Instead, just use this:

ClientScript.RegisterStartupScript(this.GetType(),"injectedClose","CloseAndRebind()",true);

I use VB and not C# so that may not be 100% correct, but that's the gist of it.

Shaun
0
Mike
Top achievements
Rank 1
answered on 23 Jul 2008, 12:29 PM
I just ended up using their example which I could not find before.

http://www.telerik.com/demos/aspnet/prometheus/Grid/Examples/DataEditing/PopUpEditForm/DefaultCS.aspx

   ClientScript.RegisterStartupScript(Page.GetType(), "ID", "CloseAndRebind();", true);   
0
Matthew Botting
Top achievements
Rank 1
answered on 13 Aug 2008, 05:10 AM
Hi guys,
I implemented a similar approach for the radWindow for ASP.NET verion of the control. Sometimes however I would get a javascript error stating that it "can't execute code from a freed script".
I got around this by wrapping the GetRadWindow().Close(); in a setTimeout wrapper with a 200ms delay
ie setTimeout('GetRadWindow().Close();',200);

Since upgrading from the ASP.NET windowmanager to the Q2 ASP.NET AJAX version I am now getting the error about the freed script again. I have tried increasing the timeout as well as using your approach as below

//clientside function
    function CloseOnReload()
    {  
        GetRadWindow().BrowserWindow.refreshGrid();
        GetRadWindow().Close();
    }

'Server code
 ClientScript.RegisterStartupScript(Page.GetType(), "TEST", "CloseOnReload();", True)

Has anyone else experienced this? Also I have been having issues with the close event not firing, so have had to disable debugging in my web.config to get around this.

Thanks
Matt
0
Georgi Tunev
Telerik team
answered on 13 Aug 2008, 06:27 AM
Hello Matthew,

"can't execute code from a freed script" error can occur if you try to execute code from an already closed and destroyed RadWindow (e.g. you have set sime timeout for the function to be executed, but the page from which it has been called is already destroyed).
Unfortunately without having a better view over your exact scenario, I cannot provide you with a suitable solution that would work in all cases, but if you open a support ticket and send me a small sample project that reproduces the problem, I will do my best to help.



Greetings,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Atiq Ur Rehman
Top achievements
Rank 1
answered on 14 Aug 2008, 02:19 PM
Hi shaun,

I am trying to do this but nothing happens in my case. Can you please help me out with the code? I am doing exactly the same thing but my child window closes it self thats it, no ajax post back nothing on the parent page.
Please help.

thanks
Atiq
0
Shaun Peet
Top achievements
Rank 2
answered on 14 Aug 2008, 08:22 PM
Hello Atiq,

I would be glad to try and help you.  Please post the code that you are using to open and to close the window.  Thanks,

Shaun.
Tags
Window
Asked by
Mike
Top achievements
Rank 1
Answers by
Shaun Peet
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Matthew Botting
Top achievements
Rank 1
Georgi Tunev
Telerik team
Atiq Ur Rehman
Top achievements
Rank 1
Share this question
or