Retry --- 无限的未知

:) 少些狂妄,少些埋怨,多点知足....保持一个好心境...

用户操作
[即时聊天] [发私信] [加为好友]
RetryID:deepbluekk
109393次访问,排名851,好友0人,关注者2人。
~~
deepbluekk的文章
原创 58 篇
翻译 0 篇
转载 156 篇
评论 17 篇
最近评论
xh_214:HttpServletRequest , response 也能这样序列化吗?最近正在写一个webserviece ,我用的是axis。服务器上的servlet我已经发布好了可就是request,response 没法传进去。能不能给指点一二。谢谢!
likeshuaigetao:很生动,很形象
forverlove:学习.
roewe:写在OnRowDataBound里面会更好一点
roewe:写在OnRowDataBound里面会更好一点
文章分类
收藏
    相册
    DotNet参考资料
    Asp.net Ajax扩展-Atlas
    C-CharpCorner
    Chinaaspx.com
    codeguru.com
    CodeProject.com
    codes-sources.com
    CodeZone
    Csharpfr.com
    csharp-source.net
    dotnetjohn.com
    DotnetNuke中国
    GotDotNet
    infragistics.com
    MSDN WebCast
    MSDN WebCast
    odetocode.com
    open-open.com
    Oracle技术资料
    pinvoke.net
    QuickStarts(asp.net2.0入门)
    Scott Guthrie 博客中文版
    sliver.com
    softpedia.com
    sourceforge.net
    Spdevelop.com
    windowsforms.net
    孟宪会asp.net
    思归的Blog
    项目管理联盟
    Java参考资料
    dev2dev.bea.com.cn
    developerWorks 中国
    http://www.javaresearch.org
    Sun技术社区(中国)
    中国Eclipse社区
    Vs.net2005
    asp.net
    codeplex.com
    MSDN2中文版
    Starter Kits
    Starter Kits
    电子书下载
    学习下载频道
    数据库参考资料
    chinaunix.net
    ITPUB.net
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 在自定义Server Control中捆绑JS文件收藏

    新一篇: ASP.NET2.0导航功能之配置会员和角色 | 旧一篇: vs2003与vs2005编译区别

    注:本文基于.NET 2.0 和 VS2005

    我们在编写 Server Control 的时候难免要用到一些客户端脚本(javascript),如何把脚本和编译好的dll一起发布就成了一个问题。把一段一段的javascript block写在cs文件里是一件很“丑陋”的事情,javascript就应呆在*.js文件里。js文件怎样才能“打包”到dll里呢?查了很多文档,最后实践下来发现有很多细节是需要注意的。整理出来,免得大家走弯路。废话无多,让我们开始。

    Step 0: 我们已有的
    1. 网站项目:Website1 ,其中:  
            Default.aspx (空页面)
    2. WebControl库项目:WebControlLibrary1 ,其中: 
            ClientScriptResourceLabel.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebControlLibrary1
    {
        
    public class ClientScriptResourceLabel : WebControl
        {

        }
    }
            script_include.js
    function DoClick() {Form1.Message.value='Text from resource script.'}

     


    Step 1:
    在script_include.js文件的属性窗口里,把Build Action改为:Embedded Resource
     


    Step 2:

    ClientScriptResourceLabel.cs 中加入

    [assembly: WebResource("script_include.js""application/x-javascript")]
    namespace WebControlLibrary1
    {
    ....
    注意这句是在namespace之外。你也可以把这句加在AssemblyInfo.cs文件里,.NET的类库就是统一加在AssemblyInfo.cs文件里的。


    很多文档(包括MSDN)里都说通过以上两步就可以把js文件作为资源,捆绑到dll中了。但实际上更不就不能用。我们用Reflector来看看编译出来的到底是什么东东。

    怎么变成 WebControlLibrary1.script_include.js 了?!问题是出在“默认名称空间”。VS会自动把default namespace加到资源文件前面。其实只要把默认名称空间该为空就可以了。令人郁闷的是VS2005正式版不允许把default namespace改为空(beta2是允许的)。怎么办呢?难道要用麻烦的命令行来编译吗?还有一个办法就是手工修改项目文件。

    Step 3:
    用写字板打开WebControlLibrary1.csproj文件,把其中的RootNamespace 改为空

      <PropertyGroup>
        
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        
    <ProductVersion>8.0.50727</ProductVersion>
        
    <SchemaVersion>2.0</SchemaVersion>
        
    <ProjectGuid>{65431F13-ABAE-4281-A860-90FEC739AFED}</ProjectGuid>
        
    <OutputType>Library</OutputType>
        
    <AppDesignerFolder>Properties</AppDesignerFolder> 
        <RootNamespace></RootNamespace>
     
        
    <AssemblyName>WebControlLibrary1.web</AssemblyName>
      
    </PropertyGroup>


    这样一来“默认名称空间”就没有了:



    Step 4:
    编译WebControlLibrary1,这下得到的是我们想要的了:


    Step 5
    : 
    调用脚本资源(ClientScriptResourceLable.cs)

        public class ClientScriptResourceLabel : WebControl
        {
            
    protected override void OnPreRender(EventArgs e)
            {
                
    if (this.Page != null)
                {
                    ClientScriptManager manager1 
    = this.Page.ClientScript;
                    manager1.RegisterClientScriptResource(
    typeof(ClientScriptResourceLabel), "script_include.js");
                }
                
    base.OnPreRender(e);
            }
        }


     

    Step 6
    终于可以在页面里使用包装好的控件了(Default.aspx):

    <%@ Page Language="C#" %>

    <%@ Register Assembly="WebControlLibrary1" Namespace="WebControlLibrary1" TagPrefix="cc1" %>
    <html>
    <head runat="server">
        
    <title>Script Resource</title>
    </head>
    <body>
        
    <form id="Form1" runat="server">
            
    <div>
                
    <input type="text" id="Message">
                
    <input type="button" onclick="DoClick()" value="ClientClick">
                
    <cc1:ClientScriptResourceLabel ID="ClientScriptResourceLabel1" runat="server" />
            
    </div>
        
    </form>
    </body>
    </html>

    生成的页面是这样的:

    <html>
    <head><title>
        Script Resource
    </title></head>
    <body>
        
    <form name="Form1" method="post" action="Default.aspx" id="Form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkwOTU4NDc0OGRkO0UjKICXV1XisDv/KKM/wA+05FQ=" />
    </div>

    <script src="/WebSite1/WebResource.axd?d=E2u_4K_tSvgEe7jglgaDJYjGQkJj2ZwZEqAWVi3afWYe4CI30IeNjer7_ojoLKjr0&amp;t=632688246616562500" type="text/javascript"></script>
            
    <div>
                
    <input type="text" id="Message">
                
    <input type="button" onclick="DoClick()" value="ClientClick">
                
    <span id="ClientScriptResourceLabel1"></span>
            
    </div>
        
    </form>
    </body>
    </html>

    其中的<script src="/WebSite1/WebResource.axd?d=...... 就是对脚本资源的调用。


    注意:除了default namespace会影响编译出来的脚本资源文件名外,文件所在的位置也会作为前缀加到文件名上。例如你把script_include.js放到 JS 目录下,编译出来就会变成 JS.scritp_include.js
     

    发表于 @ 2006年08月15日 22:28:00|评论(loading...)|编辑

    新一篇: ASP.NET2.0导航功能之配置会员和角色 | 旧一篇: vs2003与vs2005编译区别

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © Retry