[图解]ExtSharp从安装到部署运行(二)
在 SampleScript 项目中添加 ExtSharp.dll 引用,ExtSharp.dll文件在附件中可以找到!下面这一点很重要:用记事本打开 F:\ExtSharpDemo\SampleScript 这个项目的 SampleScript.csproj 文件找到:<OutputPath>..\</OutputPath>
<ScriptPath>..\..\..\App_Scripts\</ScriptPath>把这两个修改成如下:(共有两处哦)<OutputPath>..\Web\Bin</OutputPath>
<ScriptPath>..\Web\App_Scripts\</ScriptPath>把 <DocumentationFile>..\SampleScript.xml</DocumentationFile> 改成 <DocumentationFile>..\Web\Bin\SampleScript.xml</DocumentationFile>这两个修改目的是指定编译后生成的js等文件的路径到Web目录下面!继续:
附件:
您所在的用户组无法下载或查看附件在两个项目中分别添加 HelloWorld.cs 和 HelloWorld.aspx贴代码:HelloWorld.cs
using System;
using ScriptFX;
using Ext;
namespace SampleScript
{
public class HelloWorld
{
//写一个静态的main方法,每个都是的
public static void main(Dictionary args)
{
ExtClass.onReady(new AnonymousDelegate(delegate() { new HelloWorld().init(); }));
}
//定义初始化内容
public void init()
{
//弹出一个对话框,很简单的写法,有智能感知,如果写的不对会编译不通过,这样避免了JS脚本错误
MessageBox.alert("Button Click", String.Format("You clicked the button"));
}
}
}
HelloWorld.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorld" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorld" %>
<!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>Hello World</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
<script type="text/javascript" src="adapter/ext/ext-base.js" ></script>
<script type="text/javascript" src="ext-all-debug.js" ></script>
</head>
<body>
<form id="form1" runat="server">
<ssfx:Scriptlet runat="server" ID="scriptlet" EnableDebugging="True" PrecompiledScriptlet="SampleScript.HelloWorld">
<References>
<ssfx:AssemblyReference Name="sscorlib"></ssfx:AssemblyReference>
<ssfx:AssemblyReference Name="ssfx.Core"></ssfx:AssemblyReference>
<ssfx:AssemblyReference Name="ExtSharp"></ssfx:AssemblyReference>
<ssfx:AssemblyReference Name="SampleScript"></ssfx:AssemblyReference>
</References>
</ssfx:Scriptlet>
</form>
</body>
</html>
Web.config配置<?xml version="1.0"?>
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="ssfx" namespace="nStuff.ScriptSharp.Web.UI" assembly="nStuff.ScriptSharp.Web, Version=0.4.2.0, Culture=neutral, PublicKeyToken=8fc0e3af5abcb6c4"/>
</controls>
</pages>
<compilation debug="true">
<assemblies>
<add assembly="nStuff.ScriptSharp.Web, Version=0.4.2.0, Culture=neutral, PublicKeyToken=8fc0e3af5abcb6c4"/>
</assemblies>
</compilation>
<globalization fileEncoding="UTF-8" requestEncoding="UTF-8" responseEncoding="UTF-8" />
</system.web>
</configuration>
好了,编译运行吧!效果图:

附件:
您所在的用户组无法下载或查看附件整个项目的源码在附件中!这只是一个工具,帮助你快速的生成兼容性好的没有bug的javascript代码。【转自请注明出处为】