views:

118

answers:

6

So here is my basic problem.

The user clicks the save button.
Use Ajax to save the content via code-behind.
THEN open a new window that loads the content from the DB.

I just need a way to not open the window until the content has been saved. Right now it immediately opens a new window and the content isn't all saved yet.

Any ideas?

EDIT:
Sorry, I guess I should of been more clear. I'm using the asp.net updatepanel and the button I click triggers the update panel to save some information to the DB and then I want to open a new window that "previews" this new data. So here is what I have and it doesn't break, but it doesn't open a new window either.

protected void lnkPreview_Click(object sender, System.EventArgs e)
{
      temp1 control = UpdatePanel1.ContentTemplateContainer.FindControl("template") as temp1;
      control.saveContent();

      string script = "<script language='javascript'>window.open('/preview.aspx', '_blank');</script>";
      this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(),"ClientScriptStuff", script);
}
A: 

Setup the window.open() function as a callback from the AJAX result.

s_hewitt
This wouldn't be initiated by a user action, so probably blocked by a popup blocker.
spender
+4  A: 

Your AJAX call allows you to have a completion callback which will be executed when the server replies.

You need to call window.open there.
For more details, please show us your code.

However, beware of popup blockers.

SLaks
+1 for popup blockers
spender
I see what your doing, but I'm trying to do it from an updatepanel though.
Jisaak
A: 

Get the response of the save using the Ajax method and fire the window.open upon receiving the save confirmation.

Kangkan
+3  A: 

I'd consider opening a blank/alternative content window immediately upon the user action then setting the window location when the callback completes. This way you should be more immune to popup blocking.

spender
+2  A: 

Use a callback after the ajax completes to load the db content into a MODAL window.

An example using jQuery w/ the facebox plugin:

$("form").submit(function(){
    var form = $(this);
    $.ajax({
        "url" : form.attr("action")||document.location.toString(),
        "type" : form.attr("method")||"get",
        "data" : form.serialize(),
        "success" : function(data){
            $.facebox({"ajax" : "popupwindowURL.htm?data="+data});
        }
    });
    return false;
});

I just want to note that you should add an error callback to the above snippet. And you should also prevent multiple form submits.

David Murdoch
A: 
protected void lnkPreview_Click(object sender, System.EventArgs e)
{
         //Save the page content

         //Open a page to preview the changes
         ScriptManager.RegisterClientScriptBlock(UpdatePanelName, typeof(Page), "previewPage", "window.open('/preview.aspx');", true);
 }
Jisaak