ASP.NET一些常用的技巧

//如果新闻标题大于某个值就让它后面的省掉
public   string   shengyue(string   str,   int   Int)    
  {    
   if   (str.Length   <=   Int)    
   {    
    return   str;    
   }    
   else    
   {    
    str   =   str.Substring(0,Int)   +   "...";    
    return   str;    
   }    
  }
HTML代码:<%# shengyue(DataBinder.Eval(Container.DataItem,"title").ToString(),13)%>


//防止刷新重复提交:

Response.Write("<script language='javascript'>alert('信息发表成功!');window.location = '" + Request.Url +"'</script>");

//后台调用前台脚本验证代码
Button1.Attributes.Add("onclick" ,"javascript:data();");

//插入一条数据后立即获取这条ID的值
string   strSql_InsertFlow   =   "insert   into   data_news(title,body)   values('"+title.Trim()+"','"+body.Trim()+"');select   @@identity   as 'newid'";

//禁止后退按钮
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);



原文地址:https://www.cnblogs.com/AeroJin/p/1183756.html