开发者

Can I delay window.open()?

开发者 https://www.devze.com 2022-12-25 05:53 出处:网络
So here is my basic problem. The user clicks the save button. Use Ajax to save the content via code-behind.

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);
}


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.


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.


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.


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


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


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);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消