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

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值