asp.net(C#)中文乱码问题
asp.net默认的编码是UTF-8
js文件里的编码也是UTF-8
当你要在aspx页面上进行传中文参数时会出现乱码
<-----request.aspx--接收参数页----->
<----response.aspx--传送参数页----->
例一:<a href="request.aspx?str=中国人"></a>
解决办法一:
1.可以和改webconfig的编码 如:
<location path='response.aspx'>
<system.web>
<globalization fileEncoding='gb2312' requestEncoding='gb2312' responseEncoding='gb2312' culture='zh-CN'/>
</system.web>
</location>
注意:你也要把request.aspx页面上的编码也改成同样的,虽然中文乱码解决了,但如果你用到了js文件就会出现乱码
//用这以上方法的话不会改变网站的其它页面上的编码
<location path='request.aspx'>
<system.web>
<globalization fileEncoding='gb2312' requestEncoding='gb2312' responseEncoding='gb2312' culture='zh-CN'/>
</system.web>
</location>
解决办法二:
1.如果你不想动webconfig 你可以在”response.aspx.cs“里面对参数进行编码 如:response.aspx在页面上:
<a href="request.aspx?str=<%=str%>"></a>
response.cs页面上:
声明一个变量str
public string str="中国人";
str= HttpUtility.UrlEncode(str,System.Text.Encoding.GetEncoding("GB2312"));
//这时str已经是编码后的
2.而在request.aspx.cs文件中也要进行转换 如:
声明一个变量
System.Collections.Specialized.NameValueCollection gb2312=HttpUtility.Parse
相关文档:
枚举
枚举类型声明为一组相关的符号常数定义了一个类型名称。枚举用于“多项选择”场合,就是程序运行时从编译时已经设定的固定数目的“选择”中做出决定。
枚举类型(也称为枚举)为定义一组可以赋给变量的命名整数常量提供了一种有效的方法。例如,假设您必须定义一个变量,该变量 ......
If you come to ASP.NET MVC from a purely ASP.NET Web Forms background, one of the first things you are likely to notice is that all those nice easy Server Controls have disappeared. One of those is the FileUpload, and its absence seems to cause a few problems. This article looks at how to upload f ......
转载一篇关于ASP.NET页面生命周期文章,有必要了解遗一下页面初始过程到底是怎么样的
下面是ASP.NET页面初始的过程:
1. Page_Init();
2. Load ViewState;
3. Load Postback data;
4. Page_Load();
5. Handle control events;
6. Page_PreRender();
7. Page_Render();
8. Unload event;
9. Dispose method called;
......
修饰符用于声明在外部实现的方法。extern 修饰符的常见用法是在使用 Interop 服务调入非
托管代码时与 DllImport 属性一起使用;在这种情况下,该方法还必须声明为 static,如下面的示例所示:[DllImport("avifil32.dll")]
private static extern void AVIFileInit();
注意
extern 关键字还可以定义外部程序集别名,使 ......
C#画线控件的应用实例介绍之前我们要明白在C#中没有画线的控件,这里写了一个,大家分享。共有两个控件分别是画横线和画竖线的,关于怎么画斜线有兴趣的可以做一个大家分享。
C#画线控件之横线
using System;
using System.Collections;
using System.ComponentModel; ......