如何結(jié)合MS AJAX將js文件編譯到動(dòng)態(tài)鏈接庫(kù)_AJAX教程
推薦:解讀AJAX在Post中文的時(shí)候解決亂碼的方法加上設(shè)置字符編碼的方法: response.setHeader(charset,gb2312); ******************************************** 看到的說明原文如下: 用Ajax來GET回一個(gè)頁(yè)面時(shí),RESPONSETEXT里面的中文多半會(huì)出現(xiàn)亂碼,這是因?yàn)閤mlhttp在處理返回的responseText的時(shí)候
為了使javascript代碼不被竊取,我們可以將js文件編譯成動(dòng)態(tài)鏈接庫(kù)(dll)文件。下面為了演示這一功能,創(chuàng)建了一個(gè)控件。程序代碼:http://www.cnblogs.com/Files/hblynn/SampleControlsCS.rar
一、創(chuàng)建一個(gè)類庫(kù)項(xiàng)目,命名為UpdateAnimate。
二、向項(xiàng)目中添加引用System.Web, System.Drawing, System.Web.Extensions
三、向項(xiàng)目中添加一個(gè)Jscript的文件UpdatePanelAnimation.js
四、向文件中添加如下代碼:
BorderAnimation = function(color)
{
this._color = color;
}
BorderAnimation.prototype =
{
animate: function(panelElement)
{
var s = panelElement.style;
s.borderWidth = '2px';
s.borderColor = this._color;
s.borderStyle = 'solid';
window.setTimeout(
function()
{
{
s.borderWidth = 0;
}
},
500);
}
}
這段代碼中,包含一段臨時(shí)改變UpdatePanel控件樣式的方法
五、解決方案資源管理器中,右鍵查看UpdatePanelAnimation.js的屬性,把高級(jí)中的“生成操作”屬性設(shè)置成“嵌入的資源”。
六、向項(xiàng)目中添加一個(gè)類CustomControl
七、替換類中的代碼:
using System;
using System.Drawing;
using System.Web.UI;
using System.Web;
using System.Globalization;
namespace UpdateAnimate
{
public class UpdatePanelAnimationWithClientResource : Control
{
private string _updatePanelID;
private Color _borderColor;
private Boolean _animate;
public Color BorderColor
{
get
{
return _borderColor;
}
set
{
_borderColor = value;
}
}
public string UpdatePanelID
{
get
{
return _updatePanelID;
}
set
{
_updatePanelID = value;
}
}
public Boolean Animate
{
get
{
return _animate;
}
set
{
_animate = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Animate)
{
UpdatePanel updatePanel = (UpdatePanel)FindControl(UpdatePanelID);
string script = String.Format(
CultureInfo.InvariantCulture,
@"
Sys.Application.add_load(function(sender, args) {{
var {0}_borderAnimation = new BorderAnimation('{1}');
var panelElement = document.getElementById('{0}');
if (args.get_isPartialLoad()) {{
{0}_borderAnimation.animate(panelElement);
}}
}})
",
updatePanel.ClientID,
ColorTranslator.ToHtml(BorderColor));
ScriptManager.RegisterStartupScript(
this,
typeof(UpdatePanelAnimationWithClientResource),
ClientID,
script,
true);
}
}
}
}
八、向AssemblyInfo.cs文件中添加如下行:
[assembly: System.Web.UI.WebResource("UpdateAnimate.UpdatePanelAnimation.js", "application/x-javascript")]
九、生成項(xiàng)目。
控件演示:
一、創(chuàng)建一個(gè)Ajax-enabled類型的網(wǎng)站項(xiàng)目。
二、向網(wǎng)站跟目錄下添加bin目錄。
三、從控件項(xiàng)目的bin\Debug或 bin\Release目錄拷貝UpdateAnimate.dll到網(wǎng)站bin目錄里。
四、替換Default.aspx的內(nèi)容并運(yùn)行程序:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="Samples" Namespace="UpdateAnimate" Assembly="UpdateAnimate" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>ScriptReference</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
EnablePartialRendering="True"
runat="server">
<Scripts>
<asp:ScriptReference Assembly="UpdateAnimate" Name="UpdateAnimate.UpdatePanelAnimation.js" />
</Scripts>
</asp:ScriptManager>
<Samples:UpdatePanelAnimationWithClientResource
ID="UpdatePanelAnimator1"
BorderColor="Green"
Animate="true"
UpdatePanelID="UpdatePanel1"
runat="server" >
</Samples:UpdatePanelAnimationWithClientResource>
<asp:UpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar2"
runat="server">
</asp:Calendar>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
http://www.cnblogs.com/hblynn/archive/2007/02/01/637312.html
分享:談在AJAX中GET回的ResponseText中文亂碼的最簡(jiǎn)解決辦法用Ajax來GET回一個(gè)頁(yè)面時(shí),RESPONSETEXT里面的中文多半會(huì)出現(xiàn)亂碼,這是因?yàn)閤mlhttp在處理返回的responseText的時(shí)候,是把resposeBody按UTF-8編碼進(jìn)解碼考形成的,如果服務(wù)器送出的確實(shí)是UTF-8的數(shù)據(jù)流的時(shí)候漢字會(huì)正確顯示,而送出了GBK編碼流的時(shí)候就亂了。
- Ajax中瀏覽器的緩存問題解決方法
- AJAX和WebService實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)具體代碼
- ajax 登錄功能簡(jiǎn)單實(shí)現(xiàn)(未連接數(shù)據(jù)庫(kù))
- AJAX和WebService實(shí)現(xiàn)郵箱驗(yàn)證(無刷新驗(yàn)證郵件地址是否合法)
- AJAX和三層架構(gòu)實(shí)現(xiàn)分頁(yè)功能具體思路及代碼
- 使用AJAX返回WebService里的集合具體實(shí)現(xiàn)
- AJAX獲取服務(wù)器當(dāng)前時(shí)間及時(shí)間格式輸出處理
- ajax傳遞多個(gè)參數(shù)具體實(shí)現(xiàn)
- ajax傳遞一個(gè)參數(shù)具體實(shí)現(xiàn)
- 滑輪滾動(dòng)到頁(yè)面底部ajax加載數(shù)據(jù)配合jsonp實(shí)現(xiàn)探討
- jQery ajax——load()方法示例介紹
- jQuery+Ajax實(shí)現(xiàn)表格數(shù)據(jù)不同列標(biāo)題排序(為表格注入活力)
AJAX教程Rss訂閱編程教程搜索
AJAX教程推薦
猜你也喜歡看這些
- jquery ajax實(shí)現(xiàn)批量刪除具體思路及代碼
- 如何用AjaxPro實(shí)現(xiàn)定時(shí)刷新效果
- 菜鳥蔡之Ajax復(fù)習(xí)第一篇(后臺(tái)asp.net)(傳統(tǒng)的JavaScript方法實(shí)現(xiàn)Ajax功能)
- 解析AJAX進(jìn)度條
- 詳解-CSS技巧篇
- jquery ajax提交表單從action傳值到j(luò)sp實(shí)現(xiàn)小結(jié)
- 淺析AJAX初體驗(yàn)之上手篇
- AJAX教程之由省份選擇城市
- 解析ajax實(shí)現(xiàn)無刷新驗(yàn)證用戶名是否存在
- Ajax開發(fā)十個(gè)常犯的錯(cuò)誤
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索如何結(jié)合MS AJAX將js文件編譯到動(dòng)態(tài)鏈接庫(kù)
- 教程說明:
AJAX教程-如何結(jié)合MS AJAX將js文件編譯到動(dòng)態(tài)鏈接庫(kù)
。