COMPUTER_LZY

要输就输给追求,要嫁就嫁给幸福

导航

ASP.NET 一些常用的技巧

1、关闭当前页面

 

 Response.Write("<script language:javascript>javascript:window.opener=null;window.close();</script>");

2、通过session控制页面元素的显示与否

 

  <script type="text/javascript" language="javascript">
        function init()
        {
            var userName = ' <%=Session[ "UserName"]%> ';
            if (userName.trim() == "张三")
                document.getElementById("div_employee").style.display = "none";
            else
                document.getElementById("div_admin").style.display = "none";
                
            
                          
        }
    </script>

 

3、在C#后台跳转页面时,碰到母版时需要通过parent来获取母版本身的页面地址

     在当前页面当前页面跳转使用window.location

     在当前页面的母版中实现跳转时使用parent.location,

     在母版的母版中跳转使用parent.parent.location

 

Response.Write("<script language='javascript'>parent.parent.location='../Login.aspx'" + "</script>");
 

 

 4、格式化日期

string.Format("{0:yyyy-MM-dd HH:mm:ss}", Convert.ToDateTime(Request.QueryString["StartTime"]))
 

 

 

posted on 2011-12-13 15:21  CANYOUNG  阅读(223)  评论(0编辑  收藏  举报