2011-09-20 42 views
0

我有這個問題。兩頁:通過javascript在彈出窗口中調用的父項和子項。 子頁面是一個搜索頁面。在這個用戶可以選擇其中一個結果,並通過querystring和javascript重新發送到父頁面。Popup asp.net頁面,javascript和路徑錯誤404

這是我使用這樣做在search.aspx的代碼隱藏的腳本:

protected void Button4_Click(object sender, EventArgs e) 
    { 
     string url2 = ""; 

     if (GridView1.Rows.Count == 0) 
     { 
      string myStringVariable = string.Empty; 
      myStringVariable = "Nessuna ricerca effettuata!"; 
      ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true); 
     } 
     else 
     { 
      bool chk = false; 

      foreach (GridViewRow row in GridView1.Rows) 
      { 
       RadioButton rad = (RadioButton)row.FindControl("RadioButton1"); 
       Label lb1 = (Label)row.FindControl("Label1"); 

       if (rad.Checked) 
       { 
        chk = true; 
        url2 = "classmer.aspx?cod=" + lb1.Text; 
        break; 
       } 
      } 
      if (chk) 
      { 
       StringBuilder st = new StringBuilder(); 
       st.Append("<script language='javascript'>"); 
       st.Append("window.opener.location = '" + url2 + "';"); 
       st.Append("self.close();"); 
       st.Append("</script>"); 
       ClientScript.RegisterStartupScript(typeof(Page), "", st.ToString()); 
      } 
      else if (!chk) 
      { 
       string myStringVariable = string.Empty; 
       myStringVariable = "Nessun mercato selezionato!"; 
       ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true); 
      } 
     }  

現在讓我們通過對404錯誤。 父頁面有這個網址的「http://localhost/App/ClassMer/classmer.aspx」 子頁有這個網址的「http://localhost/App/ClassMer/search.aspx」

點擊搜索頁面上的確認按鈕,它將繞過「App」文件夾(這是在部署應用程序時在IIS7中創建的虛擬路徑)重新發送到此URL「http://localhost/ClassMer/classmer.aspx」。

我該如何解決這個問題?

我嘗試了一些解決方案,如添加Request.ApplicationPath或直接通過字符串指定我傳遞給javascript的URL的路徑,但沒有發生任何事情。

請幫助!

感謝

+0

您的意思是,點擊確認按鈕時,它將它們發送到classmer.aspx,而不是search.aspx? – Kasaku

+0

是的。該按鈕位於search.aspx上。通過點擊它js將重新發送到classmer.aspx並添加查詢字符串。但問題是它可以正確定位父頁面(請參閱最新的URL) – Kyashan

+0

好的,您可能想編輯您的問題,然後更正該URL以使其更容易理解。 – Kasaku

回答

0

Request.ApplicationPath應該罰款我還以爲。請嘗試以下操作:

url2 = HttpRuntime.AppDomainAppVirtualPath + "/classmer.aspx?cod=" + lb1.Text; 
+0

感謝海盜,但它不起作用:\ 同樣的錯誤和相同的請求路徑 – Kyashan

+0

你可以更新你的問題,幷包括正在寫出的彈出頁面的JavaScript?假設這是問題所在。 – Kasaku