由於使用者太習慣輸入完資料時,就按Enter鍵送出。

protected void Page_Load(object sender, EventArgs e)
{
    //註冊JS
    this.txt1.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" + this.Page.ClientScript.GetPostBackEventReference(this.btnTest1, "") + "}");
    this.txt2.Attributes.Add("onkeypress", "if( event.keyCode == 13 ) {" + this.Page.ClientScript.GetPostBackEventReference(this.btnTest2, "") + "}");
}

這裡要注意一下,必須把Button的UseSubmitBehavior屬性設定為false,這樣這Button的Type則為button,否則 預設為submit

img1.png

arrow
arrow
    文章標籤
    UseSubmitBehavior enter
    全站熱搜

    Jimmy 發表在 痞客邦 留言(0) 人氣()