asp.net母版页实现文本阅读实例
2014-12-06 12:00
531 查看
.master代码如下:
![](http://img.blog.csdn.net/20141206120528655?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWF5dW4wNTE2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
.master.cs代码如下:
readalltext.aspx代码如下:
![](http://img.blog.csdn.net/20141206120330656?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWF5dW4wNTE2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
readalltext.aspx.cs代码如下:
readallline.aspx代码如下:
</div> <asp:Button ID="btn_save" runat="server" Text="保存修改" onclick="btn_save_Click" /></asp:Content>
![](http://img.blog.csdn.net/20141206120448937?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWF5dW4wNTE2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
readallline.aspx.cs代码如下:
显示效果如下:
![](http://img.blog.csdn.net/20141206120710757?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWF5dW4wNTE2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="A_spl_02.master.cs" Inherits="A_spl_02" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="Jquery172.js" type="text/javascript"></script> <script type="text/javascript">//动态效果 $(document).ready(function () { $("#div_right div").mouseover(function () {//鼠标移入显示 $("a", this).show(); }); $("#div_right div").mouseout(function () {//鼠标移出隐藏 $("a", this).hide(); }); }); </script> <style type="text/css"> body{ width:750px; margin:0px auto;} h2{ text-align:center; border-bottom:1px dotted silver; padding-bottom:20px;} .clr{ clear:both;} #div_head {} #div_left { float:left; } #div_right { float:right; width:270px;} #div_right div { padding:10px 0px 10px 0px; border-bottom:1px dotted silver; } #div_right div a { display:block; float:right; padding:3px; border:1px solid black; font-size:12px; text-decoration:none; margin-left:5px; display:none; } #div_right div a:hover { color:#850000;} #div_foot { height:30px; background-color:#dedede; border:1px solid gray;} </style> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <div id="div_head"> <h2> 简易文本阅读编辑</h2> </div> <div id="div_main"> <div id="div_left"> <asp:ContentPlaceHolder ID="holder_main" runat="server"></asp:ContentPlaceHolder> </div> <div id="div_right" runat="server" >放菜单</div> <div class="clr"></div> </div> <div id="div_foot"></div> </div> </form> </body> </html>
.master.cs代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class A_spl_02 : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { Panel pnl_item; Label lab_fname; HyperLink hlink_alltext, hlink_lines; string[] sarr_fname = Directory.GetFiles(MapPath("txtfiles"), "*.txt"); foreach (string _s in sarr_fname) { lab_fname = new Label(); <span style="color:#ff0000;">lab_fname.Text = Path.GetFileName(_s);</span> hlink_alltext = new HyperLink(); hlink_alltext.Text = "全部读取"; hlink_alltext.NavigateUrl = "spl_02_readalltext.aspx?fname=" + lab_fname.Text;//QueryString 方式传值 hlink_lines = new HyperLink(); hlink_lines.Text = "分行读取"; hlink_lines.NavigateUrl = "spl_02_readallline.aspx?fname=" + lab_fname.Text; pnl_item = new Panel(); pnl_item.Controls.Add(lab_fname); pnl_item.Controls.Add(hlink_alltext); pnl_item.Controls.Add(hlink_lines); div_right.Controls.Add(pnl_item); } } }
readalltext.aspx代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/A_spl_02.master" AutoEventWireup="true" CodeFile="spl_02_readalltext.aspx.cs" Inherits="spl_02_readalltext" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <span style="color:#ff0000;"><asp:Content ID="Content2" ContentPlaceHolderID="holder_main" Runat="Server"> <asp:TextBox ID="txt_content" runat="server" Width="400px" TextMode="MultiLine" Rows="13"></asp:TextBox><br /> <asp:Button ID="btn_save" runat="server" Text="保存修改" onclick="btn_save_Click" /> </asp:Content></span>
readalltext.aspx.cs代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class spl_02_readalltext : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["fname"] != null) { <span style="color:#ff0000;">string _path = Path.Combine(MapPath("txtfiles"),Request["fname"]);</span> if (File.Exists(_path)) { txt_content.Text = File.ReadAllText(_path); } else { Response.Redirect("spl_02_default.aspx"); } } else { Response.Redirect("spl_02_default.aspx"); } } } protected void btn_save_Click(object sender, EventArgs e) { <span style="color:#ff0000;">string _path = Path.Combine(MapPath("txtfiles"), Request["fname"]);</span> File.WriteAllText(_path, txt_content.Text); } }
readallline.aspx代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/A_spl_02.master" AutoEventWireup="true" CodeFile="spl_02_readallline.aspx.cs" Inherits="spl_02_readallline" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> #txts_holder input { <pre name="code" class="html"><span style="color:#ff0000;">display:block;</span>width:400px;}
<span style="color: rgb(255, 0, 0);">注释:display:block;可以自动换行</span></style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="holder_main" Runat="Server" > <div id="txts_holder" style ="width:400px;" runat="server" clientidmode="Static">
</div> <asp:Button ID="btn_save" runat="server" Text="保存修改" onclick="btn_save_Click" /></asp:Content>
readallline.aspx.cs代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class spl_02_readallline : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string _path = getpath(); string[] sarr_content = File.ReadAllLines(_path); TextBox _txt; foreach (string _s in sarr_content) { _txt = new TextBox(); _txt.Text = _s; txts_holder.Controls.Add(_txt); } } protected string getpath() { string _path = ""; if (Request["fname"] == null) { Response.Redirect("spl_02_default.aspx"); } _path = Path.Combine(MapPath("txtfiles"), Request["fname"]); if (!File.Exists(_path)) { Response.Redirect("spl_02_default.aspx"); } return _path; } protected void btn_save_Click(object sender, EventArgs e) { string _content = ""; foreach (Control _ctl in txts_holder.Controls) { if (_ctl is TextBox) { _content += ((TextBox)_ctl).Text + '\u0081'; }//先将所有字符串合并成大的字符串,并用'\u0081'隔开 } _content = _content.Substring(0, _content.Length - 1);//去除最后一个<span style="font-family: Arial, Helvetica, sans-serif;">'\u0081'</span> string[] _lines = _content.Split('\u0081');//字符串分成字符串数组 string _path = Path.Combine(MapPath("txtfiles"), Request["fname"]); File.WriteAllLines(_path, _lines); } }
显示效果如下:
相关文章推荐
- asp.net 实现登陆实例
- ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
- Asp.net MVC 3实例学习之ExtShop(二)——创建母版页
- ASP.NET&Javascript实现半透明背景&模式弹出个性化页面实例
- ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
- Asp.net实现在线人数统计功能代码实例
- Asp.net MVC 3实例学习之ExtShop(二)——创建母版页
- 根据ip获取当地天气预告的实现asp.net实例
- .net实例:单点登录在ASP.NET上的简单实现(1)
- ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
- ASP.NET MVC 入门 -- 10、Action Filter 与 内置的Filter实现(实例-防盗链)
- ASP.NET中实现多文件上传的实例程序代码
- Asp.net MVC 3实例学习之ExtShop(二)——创建母版页
- JS实现复选框(Checkbox)全选和取消 --ASP.NET中实例运用
- ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
- AJAX实例:ASP.NET中的文本及包括JSON响应处理
- ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链) 【转】
- asp.net C#如何实现当地时区转换的代码实例
- asp.net+jQuery应用JSON实现无刷新三级联动实例(转)
- Asp.net MVC 3实例学习之ExtShop(二)——创建母版页