来自:http://blog.csdn.net/aigochina/article/details/8831684
C#中Server.URLEncode和Server.URLDecode是对URL进行编码和解码的方法。
今天,在项目中使用了用户控件,可是由于浏览器认为页面中有js错误,于是按钮的搜索事件无法触发。
于是,想到了使用js。
由于搜索内容可能为中文,而URL中有中文有可能会乱码,得对URL进行编码和解码:
- $(function(){
- $("#imgSearch").click(function(){
- window.location.href="sResult.aspx?keys="+EncodeURI($("#txtSearch").val());
- }):
- });
- string text="";
- try{
- text=Request.QueryString["keys"].ToString().Trim();
- }
- catch(Exception ex)
- {
- text="":
- }
URIDecode和DecodeURI有同样的功能