Reputation: 177
I have created an ASP.NET 3.5 form page. At the top I have placed some textboxes and field validators in order to insert records/rows in a database. At the bottom I have a multiview control with a view containing textboxes, validators and a gridview to search / edit the records.
Now although I can search normally with a button, if I press enter inside the search textbox, a completely irrelevant validator fires from the top of the page. The validators, textboxes, and buttons belong to different validation groups(two groups: top, bottom). Even if I turn off validation in the bottom (causesValidation = false, searchValidator = disabled) it still fires.Any ideas?
Also the bottom regex validator fires incorrectly (validationExpression = ^[a-zA-Z0-9]{1,50}$
)
while the top one which is an exact copy doesn't. I only want characters and digits inserted.
Must I check the JavaScript code? Where can I find it? Is there a command to automatically scroll to the bottom of the page after a round trip?
<asp:View ID="View2" runat="server">
ItemID Date<br/>
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="Search" CausesValidation="False"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"
ValidationGroup="Search" CausesValidation="False"></asp:TextBox>
<asp:Button ID="ButtonSearch" runat="server"
onclick="ButtonSearch_Click" Text="SEARCH" Width="120px"
ValidationGroup="Search" CausesValidation="False" />
Upvotes: 1
Views: 199
Reputation: 5650
As of ASP.NET 2.0, you can set the default button (the one that fires when the user hits the Enter key) at either the form level or the Panel level. If you haven't used Panel before, it renders as a div.
Examples:
<form id="form1" defaultbutton="SearchButton" runat="server">
<asp:Panel ID="SearchPanel" DefaultButton="SearchButton" runat="server">
Not sure, but I think the value of the defaultbutton/DefaultButton property has to be the UniqueID, not necessarily the same as the ID, of the default button.
Scott Guthrie's blog has more.
Upvotes: 1