易截截图软件、单文件、免安装、纯绿色、仅160KB

让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


相关文档:

在ASP.net中使用动态控件

经常见到有人说在ASP.net中不要使用动态控件,我想主要的原因在于使用动态控件会带来一些问题,在做项目的过程中,我将由动态加载控件引发的总是作了一个小小的总结.
    1 、在使用LoadControl加载控件后,用户控件中的某些控件不再响应事件。
    这个问题主要是由于将控件加载放在if (!Page ......

html读书笔记

     1 HTML是超文本标记语言,是浏览器的"母语",我们所看到的网页就是浏览器对HTML进行解释的结果。而XHTML是可扩展超文本标记语言,是一种新的更加结构良好的HTML语言。
    2、HTML主要是各种各样的元素,学习HTML就是学习使用这些元素。
    3、元素一 ......

Asp.net图片滚动


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="图片滑动.aspx.cs" Inherits="ASP.net.图片滑动" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    ......

IIS7发布asp.net站点

HTTP Error 500.19 - Internal Server Error
一 首先解锁
配置错误: 不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的(overrideModeDefault="Deny"),或者是通过包含 overrideMode="Deny" 或旧有的 allowOverride="false" 的位置标记明确设置的。
出现这个错误是因为 IIS 7.5 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号