views:

34

answers:

1

I have a "Save" button on a FormView with the CommandName="Update" set. This button updates an EntityDataSource that is bound to the FormView.

After the EDS is updated, I want to close this (child, popup) window and refresh my parent window (so it will reflect the changes just made to the data).

For reference, I have a similar "Cancel" button on this page that simply calls a Javascript function "OnClientClick":

function done() {
   if (window.opener.closed) {
      self.close();
   } else {
      window.opener.focus();
      window.opener.location.href = opener.location;
      self.close();
   }
}

Now, how can I let the FormView and EDS do its thing (process the Update command) and then call this javascript function (or code to accomplish the equivalent)???

After doing some more digging, I solved it. The problem had to do with the FormView being inside an Update Panel. I had to use the following:

ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, typeof(string), "done", "done();", true);
A: 

As soon as your update is finished, it should return a page that you can just register your function with. In your Update command handler (assuming this is happening server side), just add the following:

Page.RegisterStartupScript("AfterUpdate", "done();");

It will cause the done() javascript funtion to run as soon as the windows refreshes from the postback caused by the update command. If you done function isn't already in the page, make sure you add it's definition before you call it to the RegisterStartupScript call.

Kelsey
I am using an EntityDataSource bound to a FormView and I dont have a specific command handler. But, I do have an "OnUpdated" handler. I have tried adding it to this handler and I have tried adding a handler for the click event on the save button and putting it in there. The "done" function is in the master page. I have also tried putting the actual javascript code in the RegisterStartupScript instead of calling "done".Maybe just a differnece in .Net Versions, but the code I am using is:ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: done(); ", true);
Shayne
After doing some more digging, I solved it. The problem had to do with the FormView being inside an Update Panel. I had to use the following:ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, typeof(string), "done", "done();", true);
Shayne
@Shayne if this answer helped you don't forget to set the accepted answer so others don't try to answer it as well. You also get 2 rep points for setting the accepted answer :)
Kelsey