0

Is it possible to show a jQuery Modal Dialog after a Page Redirect (Full Postback) ?

I have a page:

MyEditForm.aspx/EditId=0

In that page there is a form and a SAVE button, when I click the SAVE button I want to show a jQuery Modal Dialog giving the users some options but I want to show that dialog after I redirect the user to this page:

MyEditForm.aspx/EditId=500

It's the same page but with (EditId=500)

Here's my code:

StringBuilder sb = new StringBuilder();
sb.Append("jQuery(document).ready(function () {");
sb.Append("  jQuery(function() { ");
sb.Append("    jQuery('#MyDivID').dialog({");
sb.Append("      width: 350, autoOpen: true, modal: true);
sb.Append("    });");
sb.Append("  });");
sb.Append("});");

Page.ClientScript.RegisterStartupScript(this.GetType(), "MyDialogScript", sb.ToString(), true);

Response.Redirect("~/MyEditForm.aspx/EditId=" + NewRecordId, false);

If I don't use Response.Redirect the Dialog works fine but I won't be able to redirect the user to the page with the new ID, how can I solve this?

4

1 回答 1

2

将以下代码移入 Page_Load 方法中并像这样修改

protected void Page_Load(object sender, EventArgs e){
    int editId=0;
    if(Request["EditId"]!=null and Int32.TryParse(Request["EditId"], out editId)){
       if(editId>0){
          StringBuilder sb = new StringBuilder();
          sb.Append("jQuery(document).ready(function () {");
          sb.Append("  jQuery(function() { ");
          sb.Append("    jQuery('#MyDivID').dialog({");
          sb.Append("      width: 350, autoOpen: true, modal: true);
          sb.Append("    });");
          sb.Append("  });");
          sb.Append("});");
          Page.ClientScript.RegisterStartupScript(this.GetType(), "MyDialogScript", sb.ToString(), true);
       }
    }
} 

Respon.Redirect在保存按钮单击处理程序中使用。

于 2012-11-18T20:04:39.773 回答