javascript : escape 编码与C# 的使用问题.
onsubmit="form1.Text1.value = escape(form1.Text1.value);"
.cs处理
string a = HttpUtility.UrlDecode(Text1.Value);
Response.Write(a);
Response.Write(a);
//c#实现escape编码:(用在ajax中)然后在aspx用unescape解码,就不会出现乱码问题
private string escape(string s)
{
StringBuilder sb = new StringBuilder();
byte[] ba = System.Text.Encoding.Unicode.GetBytes(s);
for (int i = 0; i < ba.Length; i += 2)
{
sb.Append("%u");
sb.Append(ba[i + 1].ToString("X2"));
sb.Append(ba[i].ToString("X2"));
}
return sb.ToString();
}
private string escape(string s)
{
StringBuilder sb = new StringBuilder();
byte[] ba = System.Text.Encoding.Unicode.GetBytes(s);
for (int i = 0; i < ba.Length; i += 2)
{
sb.Append("%u");
sb.Append(ba[i + 1].ToString("X2"));
sb.Append(ba[i].ToString("X2"));
}
return sb.ToString();
}