您的位置:首页 > 编程语言

一些常用的基础代码和技巧

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐