
Learn and download Microsoft Security Essentials
By default when you hit enter while cursor is in the TextBox, the first button on the page event gets fired.
I have added a TextBox and a Button in the aspx page like below
<
asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
And the below code in the code behind
Now run the application and hit enter key while cursor is in TextBox, you will notice that "Button1" printed on the page.
To avoid executiong of code behind of the button put
OnKeyDown = "return (event.keyCode!=13);"
in the TextBox like below
Now run the application again and hit enter key, this time Button Click even won't fire.
Happy Coding :)
<
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound"></
asp:GridView>
{
{
TextBox tbx = (TextBox)e.Row.FindControl(
"MyTextBox");RequiredFieldValidator rfv = (RequiredFieldValidator)
e.Row.FindControl(
"MyReq");Button btn = (Button)e.Row.FindControl(
"btn");tbx.ValidationGroup = validationGroupText;
rfv.ValidationGroup = validationGroupText;
btn.ValidationGroup = validationGroupText;
}
}