2012-07-06 23 views
-1

如何重定向到另一個頁面並在一個按鈕中單擊打開一個新窗口?C#ASP.NET打開新窗口並重定向按鈕單擊事件

protected void ASPxButton_save_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     //do other stuff 

     if (oSoins.DEVENIR_ECVAC_PAR != 0) 
     { 
      string AdrUrl = "Print_DosSoin.aspx?SoinId=" + Soin_Id; 
      ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", AdrUrl)); 
      } 


      Response.Redirect("DossierSoin_Liste.aspx"); 
     } 
     catch (ThreadAbortException) {/* do nothing, it might be a response.Redirect exception */} 
     catch (Exception excThrown) 
     { 
      lbl_err.Text = excThrown.Message; 
      if (excThrown.InnerException != null) lbl_err.Text += "-->" + excThrown.InnerException.Message; 
      string TempMsg = "DosSoin Fiche " + Appel_ID + "-- ASPxButton_save_Click -->" + lbl_err.Text; 
      Outils.SendingEmail(TempMsg); 
     } 

通過上面的腳本重定向,但不打開一個新窗口。

預先感謝您。

+0

您是否收到錯誤消息? – DotNetRookie 2012-07-06 12:21:19

+0

這是行不通的:你在你的頁面上註冊了一個startupscript,然後你正在執行(重定向到)另一個。 – Alex 2012-07-06 12:22:18

回答

0

您應修改您的JavaScript以下:

string script = default(string) 

if (oSoins.DEVENIR_ECVAC_PAR != 0) 
{ 
    string AdrUrl = "Print_DosSoin.aspx?SoinId=" + Soin_Id; 
    script = string.Format("window.open('{0}'); ", AdrUrl); 
} 

script += " window.location.href = 'DossierSoin_Liste.aspx';"; 

ClientScript.RegisterStartupScript(this.GetType(), "newWindow", script, true); 

這將創建那麼新窗口在客戶端上重定向。

相關問題