2014-12-04 34 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; 

     } 
相关问题