What if user simply hit ENTER instead of clicking on the button next to the text box? Because our button wasn't clicked then of course even handler for Click event won't be invoked. The problem is that users expect that hitting Enter will correctly submit the form. So what can we do?
HtmlForm and Panel classes have a property called DefaultButton. Thanks to this property we can address the issue. First lets check the HtmlForm.DefaultButton property, here is how it can be used:
1: protected void Page_Load(object sender, EventArgs e)
3: Page.Form.DefaultButton = btnSearch.UniqueID;
This is slightly more complex situation as here we would like to have Send button to be the default button for HtmlForm. So what about quick search? The following piece of code will solve it:
1: <asp:panel id="pnlSearch" runat="server" defaultbutton="btnSearchButton">
2: <asp:textbox id="txbSearchQuery" runat="server" validationgroup="search" maxlength="50" />
3: <asp:Button id="btnSearchButton" runat="server" text="Search" validationgroup="search" />
Another thing worth noticing is that defining unique validation group for all functionally related groups of controls is considered as a good practice. This way you can be sure that submitting one group won't trigger validation somewhere else.
I know that those are not a life-changing features but still I find them very useful, it's good to dust off basics like this from time to time.