2014-12-04 37 views
0

我將C#桌面應用程序轉換爲C#ASP.Net。它有一些輸出到文本文件的功能。我已經有了一個C#ASP.Net默認窗體,它執行一些用於輸出的按鈕和文本框的功能。我想爲更多功能添加更多的按鈕,並在彈出窗口中簡單地顯示從這些功能生成的文本文件輸出(我認爲這將是最簡單的,因爲我已經有桌面代碼已經這樣做)。使用我的默認表單上的按鈕,創建和顯示我的文本文件的彈出窗口的最佳方法是什麼?任何幫助將不勝感激。提前致謝。如何創建彈出窗口來顯示文本文件的內容?

回答

0

你可以先創建一個操作方法將返回文件的內容:

public ContentResult FileContent() 
    { 
     var data = string.Empty; 
     var path = @"c:\temp\output.txt"; 

     if (System.IO.File.Exists(path)) 
     { 
      data = System.IO.File.ReadAllText(path); 
     } 

     return Content(data); 
    } 

然後使用jQuery從您的行動方法提醒結果:

<script> 
$("#idOfYourButton").click(function() { 

    $.get("FileContent", function (data) { 
     alert(data); 
    }); 

}); 
</script> 
0

在你的aspx創建像這樣的彈出:

<asp:Panel ID="pseudopopup" runat="server" visible="false"> 
    // add button to close this panel 
    <table style="position: fixed; z-index: 1; left: 0px; top: 0px" border="0" width="100%" height="100%"> 
     <tr> 
      <td valign="top" align="center" > 
    <div style="width:yourwidth; margin-top:60px" class="myshadow" > 
// if file contents are large give a height and make div scrollable 
// create css to provide shadow 
    <% 
    Response.ContentType = "text/html; charset=windows-1252"; //use if html file 
    Response.WriteFile(mfile, true); %> 
    </div> 
    </td>    
     </tr> 
     </table>  
    </asp:Panel> 

在後面的代碼

public static string mfile = "" 
    protected void btn_click1(object sender, EventArgs e) 
     { 
      mfile = "~/yourfile.txt";    
      pseudopopup.Visible = true; 

     } 
相關問題