国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

為你推薦asp.net 開發的常用技巧

2024-07-10 12:53:39
字體:
來源:轉載
供稿:網友

ASP的緩存機制ASP.NET比好得多,除了總結和介紹常用的優化方法外,本文還著重介紹了如何使用ASP.NET的緩存,錯新技術頻道小編為你推薦asp.net 開發的常用技巧,一起來看看吧!
你可以在不想被緩存的頁面Page_Load事件中加上如下代碼

復制代碼 代碼如下:

Response.Expires = 0;
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
Response.AddHeader("pragma", "no-cache");
Response.CacheControl = "no-cache";


編譯成DLL:

“開始”—“運行”—“cmd” ,用下面的兩條命令編譯AuthCode.cs文件為.DLL文件。(AuthCode.cs文件保存在“C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727”目錄下)命令如下:

cd C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727
csc /target:library AuthCode.cs
GridView導出到Excel代碼2:

?

復制代碼 代碼如下:

?


public override void VerifyRenderingInServerForm(Control control)
{
//(必須有)
//base.VerifyRenderingInServerForm(control);
}
public void Generate(string Typename, string scswId, GridView TempGrid)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "utf-8";
string Filename = Typename + scswId + ".xls";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "online;filename=" + Filename);
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
TempGrid.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Write(oStringWriter.ToString());
HttpContext.Current.Response.End();
}


提示并跳轉:

?

復制代碼 代碼如下:

?


ScriptManager.RegisterStartupScript(this.Page, GetType(),
"askAndRederect", "alert('請先登錄!');window.location.href='Index.aspx';", true);


GridView中刪除某一行前詢問:

?

復制代碼 代碼如下:

?


((LinkButton)e.Row.Cells[4].Controls[2]).Attributes.Add("onclick", "javascript:return confirm('您確認要刪除嗎?')");


GridView隔行變色代碼:

?

復制代碼 代碼如下:

?


protected void GVLinkman_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//當鼠標移開時還原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}


asp.net 正則表達式:

?

復制代碼 代碼如下:

?


//驗證手機號
Regex r = new Regex(@"^(13|15|18)/d{9}$");
return r.IsMatch(mobilePhone);
//帶86或者+86的手機號
Regex regexMobile = new Regex(@"^((/+86)|(86))?(13|15|18)/d{9}$");
//驗證是否為中文
Regex regex = new Regex("^[一-龥]+$");
//Decimal(8,4)類型小數的驗證
Regex rx = new Regex(@"^-?(?:[1-9][0-9]{0,3}|0)(?:/.[0-9]{1,4})?$");
//驗證輸入是否為數字和字母的組合
regex = new Regex("^[一-龥_a-zA-Z0-9]+$");
//驗證輸入是否全為數字
regex = new Regex("^[0-9]+$");
//驗證輸入是否全為中文
regex = new Regex("^[一-龥]+$");
//電子郵件
regex=new Regex(@"^([/w-/.]+)@((/[[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}/.)|(([/w-]+/.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(/]?)$");
//驗證網址
regex = new Regex(@"http(s)?://([/w-]+/.)+[/w-]+(/[/w- ./?%&=]*)?");
//電話號碼
regex = new Regex(@"(/d{3})?/d{8}|(/d{4})(/d{7})");


將Button關聯上回車鍵的JS方法:

在網頁中設置回車鍵的解決方法是使用javascript的document.onkeydown()方法捕捉鍵盤點擊事件,使用event.keyCode來獲取用戶點擊的鍵位。

?

復制代碼 代碼如下:

?


function document.onkeydown()
{
if(event.keyCode == 13)
{
button.click();//點擊回車鍵調用button的點擊事件
event.returnValue = false;//取消回車鍵的默認操作
}
}


如果button按鈕為服務器端的按鈕,則更改如下

?

復制代碼 代碼如下:

?


function document.onkeydown()
{
//使用document.getElementById獲取到按鈕對象
var button = document.getElementById('<=serverButton.ClientID%>');
if(event.keyCode == 13)
{
button.click();
event.returnValue = false;
}
}

上文是錯新技術頻道小編為你推薦asp.net 開發的常用技巧,大家都有了一定的了解,想要學習更多的技術知識,請繼續關注錯新技術頻道!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安宁市| 南皮县| 武冈市| 孟州市| 稷山县| 新野县| 来凤县| 商水县| 澜沧| 嘉峪关市| 恩平市| 博野县| 剑川县| 大厂| 林甸县| 阿拉善左旗| 申扎县| 利川市| 龙江县| 辽宁省| 沙坪坝区| 中江县| 会昌县| 龙川县| 嵊州市| 威远县| 南投县| 马尔康县| 博爱县| 遵义市| 长武县| 句容市| 广昌县| 新野县| 秦皇岛市| 白山市| 天柱县| 濉溪县| 东港市| 澄江县| 临西县|