1

I have a login page in my asp.net website (using C#) and it has a "login form" which has an email text box, a password text box and a login button.

In addition, I have a "search form" at the top of the web page which has a search text box and a search button.

*All of the controls are in the same form because of the asp.net limit for one runat="server" form.

The problem is that when I type something to search for and click ENTER (and not directly the button) it doesn't do anything, only runs the Page_Load again. Same thing when I click ENTER in the login section instead of directly on the login button.

I have tried different solutions but they were problematic because of the different functionality of the two "forms".

I have no idea how to solve this, any suggestions?

2 Answers 2

1

my web forms is a little rusty but I think something like this:

<asp:Panel ID="loginPanel" runat="server" DefaultButton="loginButton">
<%-- Login Stuff--%>
<asp:Button ID="loginButton" runat="server" />
</asp:Panel>


<asp:Panel ID="loginPanel" runat="server" DefaultButton="searchButton">
<%-- Search Stuff --%>
<asp:Button ID="searchButton" runat="server" />
</asp:Panel>

should work

Sign up to request clarification or add additional context in comments.

3 Comments

Yep, this should do it. Also you can use the ValidationGroup attribute to trigger specific validation controls (or not) depending on which button was clicked.
That works :) I converted the search to normal html for simplicity, but this solved the ENTER issue. Is that the only way to change the default button of a web page?
In web forms i think default button is the only way to go. In mvc or vanilla html you can just use multiple forms.
0

Only one form with runat='server' available on aspx page. So, if you really need another form, you may use its without runat='server' and use for search jQuery ajax call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.