把js文件編譯成dll供頁面調(diào)用的方法
1. 在解決方案中添加一個項目:JSControl
2. 在這個項目添加一個js文件(JScript1.js)
腳本的內(nèi)容:
function showAlert(){ alert('Today is a good dary'); }
3. 改變JScript1.js的屬性,Build Action為Embedded Resource(嵌入的資源)
4. 在JSControl項目的AssemblyInfo.cs文件中添加一行:(注意JSControl.JScript1.js,JSControl是命名空間,JScript1.js是文件名)
[assembly: System.Web.UI.WebResource("JSControl.JScript1.js", "application/x-javascript")]
5. 項目中增加一個注冊客戶端腳本的類:
namespace JSControl { public class Class1 : System.Web.UI.WebControls.WebControl { protected override void OnPreRender(EventArgs e) { if (this.Page != null) { ClientScriptManager manager = this.Page.ClientScript; manager.RegisterClientScriptResource(typeof(Class1), "JSControl.JScript1.js"); } base.OnPreRender(e); } } }
6. 在調(diào)用js的項目中添加JSControl.dll的引用
7. 要調(diào)用腳本的頁面注冊JSControl.dll
<%@ Register Assembly="JSControl" Namespace="JSControl" TagPrefix="zhi" %> <!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></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <zhi:Class1 ID="rs1" runat ="server"/> </head>
8. 調(diào)用
<script type="text/javascript"> $(function () { showAlert(); }); </script>
相關(guān)文章
asp.net下常用的加密算法MD5、SHA-1應(yīng)用代碼
在進(jìn)行軟件開發(fā)的過程中,為了提高系統(tǒng)的安全性能,經(jīng)常需要進(jìn)行敏感信息的加密處理。特別是在密碼儲存、文件傳輸、頁面?zhèn)髦档确矫妫瑢π畔⑦M(jìn)行加密顯得十分必要。下面介紹我們常用的兩種加密算法MD5、SHA1。2008-09-09ASP.NET中iframe框架點擊左邊頁面鏈接 右邊顯示鏈接頁面內(nèi)容
這篇文章主要介紹了ASP.NET中iframe框架點擊左邊頁面鏈接,右邊顯示鏈接頁面內(nèi)容的實現(xiàn)代碼,感興趣的小伙伴們可以參考一下2016-07-07ASP.NET Web API教程 創(chuàng)建Admin控制器實例分享
在本文中我們要添加一個對產(chǎn)品支持CRUD(創(chuàng)建、讀取、更新和刪除)操作的Web API控制器,需要的朋友可以參考下2012-11-11