简体   繁体   中英

Enter key firing Gridview Row Command Event

I have a textbox and a gridview right below that on an aspx page. When ever I get to the page and press enter, it fires gridview onrowcommand event. Can anyone tell me what is going on here? I did google everyone suggested me to add a piece of javascript code to handle enter key event (13) . I want to know why would a page do that. Is it a web form thing or something else?

What you're witnessing is the default behavior much like hitting enter on an HTML input tag nested within form tag.

If you don't want the behavior, then you can handle it either in JavaScript as your research suggested it or in your C# code as follows:

protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Attributes.Add("onkeypress", "javascript:if (event.keyCode == 13) { 
        // do whatever you want with the event
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM