Reputation: 1185
This may be an easy question for you guys. I have a web form with several buttons and only one textbox. When I enter a value in the textbox and press enter the method gets executed that is wired to the first top left button. I need to control what button's method gets executed (in this case it is a button in a whole different location that does db query). I tried to alter tab index to have my desired button the lowest and I tried to pass focus to my desired button on page_load (like I would have done in Win Forms) but still if I enter text in textbox and hit eneter, the top left button's method gets executed. I could put conditions in execution of top left button's method but that would be a workaround not a solution. So how do I control that behavior?
Upvotes: 1
Views: 66
Reputation: 39777
ASP.NET form has a defaultbutton property that specifies which button is clicked when ENTER is pressed. Just specify your button ID there. E.g.
<form id="form1" runat="server" defaultbutton="MyDbQueryButton">
Upvotes: 1