asp.net-母版页实用测试
来源:互联网 发布:软件测试自动化书籍 编辑:程序博客网 时间:2024/06/07 18:50
母版页A_TEST.master代码如下:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="A_TEST.master.cs" Inherits="A_TEST" %><!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> <style type="text/css"> #div_head{ text-align:center; background-color:Gray; height:60px;} #div_body{ width:750px;background-color:Green;} #div_left{ float:left; width:700px;background-color:Orange; height:500px;} #div_right{ float:right; width:400px; height:500px; background-color:Orange; } #div_right div{ padding:10px 5px 10px 5px; border-bottom:1px dotted silver; } #div_right div a{ display:block; float:right; padding:3px; border:1px solid blank; text-decoration:none;} #div_right div a:hover{ color:Black;} .clr{ clear:both;} #div_foot { height:50px; background-color:Olive;} </style> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder></head><body> <form id="form1" runat="server"> <div><div id="div_head"><h1>母版页实例</h1></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>A_TEST.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_TEST : 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("files"), "*.txt"); foreach (string _s in sarr_fname) { lab_fname = new Label(); lab_fname.Text = Path.GetFileName(_s); hlink_alltext = new HyperLink(); hlink_alltext.Text = "全部读取"; hlink_alltext.NavigateUrl = "readalltext.aspx?fname="+lab_fname.Text; hlink_lines = new HyperLink(); hlink_lines.Text = "分行读取"; hlink_lines.NavigateUrl = "readalllines.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); } }}
母版页首页.aspx代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/A_TEST.master" AutoEventWireup="true" CodeFile="母版页练习.aspx.cs" Inherits="母版页练习" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="holder_main" Runat="Server"></asp:Content>
新建两个页面 readalltext.aspx和readalllines.aspx。设置母版页为A_TEST.master
readalltext.aspx代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/A_TEST.master" AutoEventWireup="true" CodeFile="readalltext.aspx.cs" Inherits="readalltext" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="holder_main" Runat="Server"> <asp:TextBox ID="txt_content" runat="server" Height="225px" Width="254px" TextMode="MultiLine" Rows="13"></asp:TextBox> <asp:Button ID="btn_save" runat="server" Text="保存" onclick="btn_save_Click" /></asp:Content>
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 readalltext : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["fname"] != null) { string _path = Path.Combine(MapPath("files"), Request["fname"]); if (File.Exists(_path)) { txt_content.Text = File.ReadAllText(_path); } else { Response.Redirect("母版页练习.aspx"); } } else { Response.Redirect("母版页练习.aspx"); } } } protected void btn_save_Click(object sender, EventArgs e) { string _path = Path.Combine(MapPath("files"), Request["fname"]); File.WriteAllText(_path, txt_content.Text); }}
效果如图:
0 0
- asp.net-母版页实用测试
- asp.net 母版页
- asp.net---母版页
- asp.net 母版页
- ASP.net 母版页
- ASP.NET 母版页 (MSDN)
- ASP.NET 母版页概述
- Asp.net母版页编程
- ASP.NET中的母版页
- Asp .net MasterPageFile母版页
- asp.net-母版页设计
- asp.net 母版页技术
- ASP.NET 母版页概述
- Asp.net中的母版页
- asp.net webfrom母版页
- ASP.NET中的母版页
- ASP.NET:母版页与内容页
- ASP.NET:母版页与内容页
- 动态规划--HDU--1024
- 第十一周项目1-函数版星号图2
- 第11周项目2-求最大公约数(1)
- Adapter 适配器模式
- 第11周项目1(2)-三角形星号图
- asp.net-母版页实用测试
- 5个简单方式使用strace场景
- pomelo 相关
- 第十一周项目6-回文&素数(二) .
- 第11周项目1函数版星号图(1)
- adb
- ffmpeg新版与旧版数据结构不同 持续更新.....
- iplimage 像素访问
- 云计算设计模式(十二)——索引表模式