一些常用的基础代码和技巧
2010-02-02 15:17
369 查看
1、向页面输出js代码
Page.ClientScript.RegisterStartupScript(Page.GetType(), "",
"<script type='text/javascript'>alert('删除成功')</script>");
2获取webconfig常量
System.Configuration.ConfigurationManager.ConnectionStrings["DbProvider.ConnectionString"];
3反序列化
JSONObject<MoveInfo> obj = Newtonsoft.Json.JavaScriptConvert.DeserializeObject<JSONObject<MoveInfo>>(strJSON);
string msg=obj.msg;
string success=obj.success;
MoveInfo info=obj.Object;
4 ession每次过期都要经过glable文件中的Application_Error方法,在其中验证,判断返回登陆页面就可以了
protected void Application_Error(Object sender, EventArgs e)
{
string URL = HttpContext.Current.Request.Url.ToString ();
if(Server.GetLastError() is HttpUnhandledException)
{
Server.ClearError();
this.Server.Transfer("Login.aspx?ref=viewstate",true);
}
else
{
Server.ClearError();
this.Server.Transfer(URL,true);
}
5 cookie中文乱码问题解决
public FLogon UserInfo {
get {
string data = HttpContext.Current.Request.Cookies.Get("UserInfo").Value.ToString();
return JsonSer.Deserialize<FLogon>(HttpUtility.UrlDecode(data));
//return (FLogon)System.Web.HttpContext.Current.Session["UserInfo"];
}
set {
string data= JsonSer.Serialize(value);
HttpCookie userinfo = new HttpCookie("UserInfo",HttpUtility.UrlEncode(data));
userinfo.Expires = DateTime.MaxValue;
HttpContext.Current.Response.Cookies.Add(userinfo);
//System.Web.HttpContext.Current.Session["UserInfo"] = value;
}
}
6 固定表头
fixed-div :外层div
.fixed-div TABLE {
/*border: 1px #19197a solid;*/
border-collapse: collapse;
table-layout:fixed;
margin-top: -1px;
/* margin-top: -1px; */
}
.fixed-div TABLE TD {
border: 1px solid;
height: 1.8em;
word-break:break-all;
}
.fixed-div TABLE TH {
background-color:#157da4;
color: #ffffff;
border: 1px solid;
height: 1.8em;
padding-left: 1em;
text-align:center;
word-break:break-all;
position: relative;
border-right:0;
border-bottom:0;
}
.fixed-div TABLE THEAD TH {
padding-left: 1px;
text-align: center;
white-space: wrap;
}
.fixed-div {
overflow-y:scroll;
text-align:center;
height:350px;
}
Page.ClientScript.RegisterStartupScript(Page.GetType(), "",
"<script type='text/javascript'>alert('删除成功')</script>");
2获取webconfig常量
System.Configuration.ConfigurationManager.ConnectionStrings["DbProvider.ConnectionString"];
3反序列化
JSONObject<MoveInfo> obj = Newtonsoft.Json.JavaScriptConvert.DeserializeObject<JSONObject<MoveInfo>>(strJSON);
string msg=obj.msg;
string success=obj.success;
MoveInfo info=obj.Object;
4 ession每次过期都要经过glable文件中的Application_Error方法,在其中验证,判断返回登陆页面就可以了
protected void Application_Error(Object sender, EventArgs e)
{
string URL = HttpContext.Current.Request.Url.ToString ();
if(Server.GetLastError() is HttpUnhandledException)
{
Server.ClearError();
this.Server.Transfer("Login.aspx?ref=viewstate",true);
}
else
{
Server.ClearError();
this.Server.Transfer(URL,true);
}
5 cookie中文乱码问题解决
public FLogon UserInfo {
get {
string data = HttpContext.Current.Request.Cookies.Get("UserInfo").Value.ToString();
return JsonSer.Deserialize<FLogon>(HttpUtility.UrlDecode(data));
//return (FLogon)System.Web.HttpContext.Current.Session["UserInfo"];
}
set {
string data= JsonSer.Serialize(value);
HttpCookie userinfo = new HttpCookie("UserInfo",HttpUtility.UrlEncode(data));
userinfo.Expires = DateTime.MaxValue;
HttpContext.Current.Response.Cookies.Add(userinfo);
//System.Web.HttpContext.Current.Session["UserInfo"] = value;
}
}
6 固定表头
fixed-div :外层div
.fixed-div TABLE {
/*border: 1px #19197a solid;*/
border-collapse: collapse;
table-layout:fixed;
margin-top: -1px;
/* margin-top: -1px; */
}
.fixed-div TABLE TD {
border: 1px solid;
height: 1.8em;
word-break:break-all;
}
.fixed-div TABLE TH {
background-color:#157da4;
color: #ffffff;
border: 1px solid;
height: 1.8em;
padding-left: 1em;
text-align:center;
word-break:break-all;
position: relative;
border-right:0;
border-bottom:0;
}
.fixed-div TABLE THEAD TH {
padding-left: 1px;
text-align: center;
white-space: wrap;
}
.fixed-div {
overflow-y:scroll;
text-align:center;
height:350px;
}
相关文章推荐
- C# 一些常用的技巧代码
- JAVA基础应用——日期/UUID等一些常用代码
- java–Servlet基础 Servlet的一些技巧&模板代码 Request相关
- 敲代码时的一些常用技巧
- C语言系列(三):最近重拾C语言的想法,谈到C中易错点,难点;以及开源代码中C语言的一些常用技巧,以及如何利用define、typedef、const等写健壮的C程序
- C语言系列(四):最近重拾C语言的想法,谈到C中易错点,难点;以及开源代码中C语言的一些常用技巧,以及如何利用define、typedef、const等写健壮的C程序
- 一些常用代码编辑工具的使用技巧小结
- C语言系列(二):最近重拾C语言的想法,谈到C中易错点,难点;以及开源代码中C语言的一些常用技巧,以及如何利用define、typedef、const等写健壮的C程序
- <android> 常用但容易忘记的一些代码和技巧 汇总(个人笔记)
- 一些常用代码编辑器(Vi、gedit、EditPlus、SourceInsight)的使用技巧小结
- C语言系列(一):最近重拾C语言的想法,谈到C中易错点,难点;以及开源代码中C语言的一些常用技巧,以及如何利用define、typedef、const等写健壮的C程序
- 一些web开发中常用的、做成cs文件的js代码 - 转帖来的
- javascript 常用代码技巧大收集
- java代码优化的常用技巧
- Vim 实用技巧,一些自己常用到的命令
- 学习javascript点滴总结,包括一些常用代码1
- 内存管理---编写安全的代码的一些技巧 C++
- 整理了一些asp初学者常用的代码 (1)
- 每个ASP程序员常用的一些知识(基础)
- JavaScript里最常用的十种代码简写技巧