让ASP.Net HTML页面代码 清爽起来
自从用了 ASP.Net MVC后就喜欢上了它 ,因为MVC对服务器控件的依赖大大减少,它生成的HTML页面就比WebForm清爽多了,加载速度有了明显的改善。
但对于页面中内嵌script,还是不能彻底的避免,如:
<script type="text/javascript" language="javascript">
//<!--
function DepositPage() {
// 这是一个第3方的WebControl,由于是服务器控件,受MasterPage影响,它的客户端ID并不是确定的。
this.ctrlRadGrid = "#<%= ctrlRadGrid.ClientID %>";
// 这是一段又臭又长的JSON,从Modal中传递过来
this.accounts = <%= Modal.JSON %>;
// .............................
}
new DepositPage();
// -->
</script>
是否有一种方法可以将这段JS不内嵌在HTML中,使用<script src="">标记从外部文件加载?
答案是肯定的,通过自定义WebControl完全可以实现,有如下WebControl
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
[ParseChildren(false)]
public class ExternalJavascriptControl : WebControl
{
private string SafeFilenamePrefix
{
get
{
return Regex.Replace( this.ClientID
, "(\\\\|\\/|\\:|\\*|\\?|\\\"|\\<|\\>|\\|)"
, "_"
, RegexOptions.ECMAScript | RegexOptions.Compiled
);
}
}
protected override void Render(HtmlTextWriter writer)
{
if (!Visible)
return;
try
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
base.Render(htw);
// get the rendered content
string rendered = sw.ToString();
// remove the script tag if exist
rendered = Regex.Replace(rendered
, @"(<[\s\/]*script\b[^>]*>)"
, string.Empty
, RegexOptions.ECMAScript | RegexOptions.Compiled | RegexOptions.IgnoreCase
);
// get the file pa
相关文档:
<html>
<head>
<title>标题<title>
</head>
<body>..........文件内容..........
</body>
</html>
1.文件标题
<title>..........</title>
2.文件更新--<meta>
【1】10秒后自动更新一次
<meta http-equiv="refresh" content=10>
【2】10秒后自动连结到另一文件
<meta http-equiv="ref ......
<!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>
<meta NAME="Copyright" CONTENT="">
<meta http-equiv="Content-Type" content="text/html; charset=u ......
1 HTML是超文本标记语言,是浏览器的"母语",我们所看到的网页就是浏览器对HTML进行解释的结果。而XHTML是可扩展超文本标记语言,是一种新的更加结构良好的HTML语言。
2、HTML主要是各种各样的元素,学习HTML就是学习使用这些元素。
3、元素一 ......
快捷键 功能
CTRL + SHIFT + B生成解决方案
CTRL + F7 生成编译
CTRL + O 打开文件
CTRL + SHIFT + O打开项目
CTRL + SHIFT + C显示类视图窗口
F4 显示属性窗口
SHIFT + F4显示项目属性窗口
CTRL + SHIFT + E显示资源视图
F12 转到定义
CTRL + F12转到声明
CTRL + ALT + J对象浏览
CTRL + ALT + F1 ......