2012-07-10 21 views
1

即時通訊從window.showModalDialog的javascript打開一個網頁(Clock.aspx)。在Clock.aspx我有一個按鈕,我想當用戶點擊該按鈕時,Clock.aspx頁面將被關閉。我不想使用javascript的onClientClick()方法作爲一些服務器端數據庫插入正在進行和插入後我想要關閉此頁面。javascript的ShowModalDialog不關閉ASP代碼後面,並打開同一頁面的新彈出

按鈕的背後的代碼如下: -

protected void btnStop_Click(object sender, EventArgs e) 
    { 
     _nonProduction = new NonProduction(); 
     if (Session["LastNonProdTimeID"] == null) 
     { 
     } 
     else 
     { 
      int NonProdTimeEntryID = Convert.ToInt32(Session["LastNonProdTimeID"]); 
      //Updating the TimeSpent 
      isTimeSpentUpdated = _nonProduction.UpdateTimeSpentInDB(NonProdTimeEntryID); 
      if (isTimeSpentUpdated == true) 
      { 

       string timespent = Convert.ToString(_nonProduction.GetTimeSpent(NonProdTimeEntryID)); 
       string msg = "Total time consumed in " +HiddenTaskname.Value.ToString()+": " + timespent.ToString() + " Minutes"; 
       ClientScript.RegisterStartupScript(typeof(Page), "closePage", "<script type='text/JavaScript'>window.close();</script>"); 

       //ShowPopUpMsg(msg); 
      } 
      else 
      { 
      } 
     } 



    } 

這裏當I M點擊按鈕多一個(Clock.aspx)彈出被顯現和窗口未關閉。請幫我看看如何關閉服務器端代碼中的ShowModalDialog。我也在頁面中使用腳本管理器。 在此先感謝。

回答

1

我又增加了<base target="_self">到clock.aspx頁面的頭部部分工作,然後對我來說工作正常。

0

對於我的,我有一個正常的JavaScript函數,關閉aspx中的頁面。

在後面的代碼中,如果更新成功,它會調用該函數。

// this function is to be called by the popup windows to refresh the opener using specific office code, and close self 
function allDoneOffice(office) 
{ 
    var opener = self.opener; 
    if (opener.doRefresh) opener.doRefreshWithOfficeCode(office); 
    window.open('','_self',''); // IE warning hack 
    self.close(); 
} 


     // update the record 
    bool b = report.SaveModifiedToDB(); 
    if (b) 
    { 
     // don't close the page if nothing was updated 
     ClientScript.RegisterStartupScript(this.GetType(), "load", "<script type=\"text/javascript\">\n" + 
     "allDoneOffice('" + report.OfficeCode + "');" + "<" + "/script>"); 
    } 
    else 
    { 
     lblResults.Text += " Unable to save modified report to the database."; 
    } 
+0

按照你的實現代碼,但仍然得到同樣的問題,當我點擊按鈕,它打開一個新的彈出clock.aspx頁面,但窗口不閉幕。我也改變了你的代碼的功能然後調用我的代碼,但是一旦我點擊一個新的Clock.aspx彈出窗口即將到來,但現在關閉網頁。 – 2012-07-11 04:57:04

0

使用下面這段代碼應該在IE

Response.Write("<script language='javascript'> { self.close() }</script>"); 
+0

按照你的實現代碼,但仍然得到同樣的問題,當我點擊它打開clock.aspx頁面的新彈出按鈕,但窗口不關閉。 – 2012-07-11 04:55:41

相關問題