ASP.NET自动生成页面后台代码
声明:
只提供后台.cs文件代码
详细教程地址:http://download.csdn.net/source/2289546
1.需要 编写静态模板页 我使用的是 template.htm
2.在模板页中定义htmlyem标记,标记非固定内容,在后台代码中为标记赋值
3.后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strDate = DateTime.Now.ToString("yyyyMMddHHmmssms");//以此为生成的静态页面命名-不会重复
string[] format = new string[4];//定义和htmlyem标记数目一致的数组
StringBuilder htmltext = new StringBuilder();
try
{
using (StreamReader sr = new StreamReader("G:/ASP.NET/StaticPages/template.htm"))//此路径 为绝对路径 指向 模板页template.htm
{
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch
{
Response.Write("<Script>alert('读取文件错误')</Script>");
}
//---------------------给标记数组赋值------------
format[0] = "自动生成静态页面"; //标题<title></title>
format[1] = "background-color:#336699;";//页面背景颜色
format[2] = "<marquee>生成的模板html页面</marquee>";//文字说明
format[3] = ftb.Text;//页面 AGStaticPages.aspx 传过来的文本
//----------替换htm里的标记为你想加的内容
for (int i = 0; i < 4; i++)
{
htmltext.Replace("$htmlformat" + i, format[i]);
相关文档:
AJAX是Asynchronous JavaScript and XML缩写。这个概念代表的是一种技术,当您在说“我在项目中使用了AJAX技术时”,只是代表了您使用客户端XMLHttpRequest对象与服务器端进行异步通信。不过因为随着AJAX技术的运用往往会带来丰富的客户端效果,因此对AJAX技术的广义理解也可以认为这是一种操作 ......
在网页的开发中为了搜索引擎的优化,添加页面的title
keyword description是最常用的方法之一。
asp.net的方法代码如下所示:
public void SEO_HEAD(string title, string keyword, string
description)
{
......
private void btnUploadPicture_Click(object sender, System.EventArgs e)
{
//检查上传文件的格式是否有效
if(this.UploadFile.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
&n ......
Cookie 提供了一种在 Web 应用程序中存储用户特定信息的方法。例如,当用户访问您的站点时,您可以使用 Cookie 存储用户首选项或其他信息。当该用户再次访问您的网站时,应用程序便可以检索以前存储的信息。
什么是 Cookie?
Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递。Cookie 包含每 ......
连接access数据库代码,写在一个单独的类里
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace AppWebDLL
{
public class ConnApp
{
  ......