日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

如何結(jié)合MS AJAX將js文件編譯到動態(tài)鏈接庫_AJAX教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:解讀AJAX在Post中文的時候解決亂碼的方法
加上設(shè)置字符編碼的方法: response.setHeader(charset,gb2312); ******************************************** 看到的說明原文如下: 用Ajax來GET回一個頁面時,RESPONSETEXT里面的中文多半會出現(xiàn)亂碼,這是因為xmlhttp在處理返回的responseText的時候

為了使javascript代碼不被竊取,我們可以將js文件編譯成動態(tài)鏈接庫(dll)文件。下面為了演示這一功能,創(chuàng)建了一個控件。

程序代碼:http://www.cnblogs.com/Files/hblynn/SampleControlsCS.rar

一、創(chuàng)建一個類庫項目,命名為UpdateAnimate。

二、向項目中添加引用System.Web, System.Drawing, System.Web.Extensions

三、向項目中添加一個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);
}
}


這段代碼中,包含一段臨時改變UpdatePanel控件樣式的方法

五、解決方案資源管理器中,右鍵查看UpdatePanelAnimation.js的屬性,把高級中的“生成操作”屬性設(shè)置成“嵌入的資源”。

六、向項目中添加一個類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")]

九、生成項目。

控件演示:

一、創(chuàng)建一個Ajax-enabled類型的網(wǎng)站項目。

二、向網(wǎng)站跟目錄下添加bin目錄。

三、從控件項目的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中文亂碼的最簡解決辦法
用Ajax來GET回一個頁面時,RESPONSETEXT里面的中文多半會出現(xiàn)亂碼,這是因為xmlhttp在處理返回的responseText的時候,是把resposeBody按UTF-8編碼進(jìn)解碼考形成的,如果服務(wù)器送出的確實是UTF-8的數(shù)據(jù)流的時候漢字會正確顯示,而送出了GBK編碼流的時候就亂了。

來源:模板無憂//所屬分類:AJAX教程/更新時間:2010-01-30
相關(guān)AJAX教程