간단한방법

ImageButtonSearchBtn 이미지버튼

TextBoxSearchText 텍스트 박스

TextBoxSearchText.Attributes.Add("onkeypress", "if (event.keyCode == 13) {" +this.Page.GetPostBackEventReference(ImageButtonSearchBtn) + "; return false;}");

.CS

public partial class top2 : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e) {

        if (!IsPostBack) {
        }

//테스트박스에서 키를 눌렀을때 자바스크립트로  이벤트코드를 캐취해서
13을 뒤져서 실행시킴   

this.SearchC.Attributes.Add("onkeydown", "CheckSubmit('"+this.ImageButton1.ClientID+"')");
    }

//실행될 버튼

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("/Search/Search.aspx?query="+ Server.UrlEncode( this.SearchC.Value ) );
    }
}

.ASPX

//SearchSubmitID 이미지 버튼

function CheckSubmit(SearchSubmitID ){
            if (event.keyCode == 13) {            
                    document.getElementById(SearchSubmitID).focus();      
     }else{
             return;
     }
}

+ Recent posts