2011-07-14 196 views
-5

我喜歡在我的項目中打開一個新窗口。我在我的項目中使用兩個面板當我點擊gridview(panel1)中的「Viewdocument」鏈接時,它應該顯示打開該文件的窗口。但在我的代碼中,它不工作,任何人都可以幫助我解決這個問題。這是代碼。如何在C中打開新窗口#

if (myReader.Read()) 
       { 
        myReader.Close(); 
        openWIndow("fr_OpenFile.aspx", "", fileName); 
        Linkbutton_ModalPopupExtender.Show(); 
        //OpenMyFile(); 
       } 
       else 
       { 
        myReader.Close(); 
        Message("Cannot open selected file"); 
        Linkbutton_ModalPopupExtender.Show(); 
        return; 
       } 
       con.Close(); 
       //OpenMyFile(); 
      } 
      else 
      { 
       Message("File not found"); 
       Linkbutton_ModalPopupExtender.Show(); 

      } 

     } 
     catch (Exception ex) 
     { 
      lblmsg.Text = ex.Message; 
     } 

    } 
private void openWIndow(String FileName, String WindowName, String qString) 
    { 
     String fileNQuery = FileName + "?value=" + qString; 
     String script = @"<script language=""javascript"">" + "window.open(" + fileNQuery + WindowName + "," + "menubar=Yes,toolbar=No,resizable=Yes,scrollbars=Yes,status=yes" + ");" + "</script>"; 
     ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", script); 
    } 

由於提前

+2

什麼是您的案例中的「打開新窗口」?打開一個Aspx頁面? –

回答

3

方法有很多種。你可以通過在asp.net超鏈接控件中簡單地使用target =「_ blank」來實現。你可以在JavaScript中使用window.open()函數來做到這一點。你甚至可以從後面的asp.net代碼註冊這個JavaScript代碼。所有的細節在這裏討論如何在asp.net中打開新窗口,C#使用JavaScript?按照http://dotnetspidor.blogspot.com/2009/01/open-new-window-in-aspnet-web-page_28.html