3

enter image description here

I have 3 different submit buttons(Log In, Search, Insert) in the same page and what I want is to find the best way to have this 3 buttons doing a different things when I press them, or I press enter while I am about to press them. As you can see from my photo, when I press Log In the Insert is pressed too because I have a global form in my Master Page.

I tried to use different forms, but i can't because I need them to have runat="server", which is not possible for a page to have.

I use asp Texboxes:

<asp:TextBox class="text-input" ID="txtLoginEmail" runat="server"
Height="15px" Width="130px"></asp:TextBox>

and asp Buttons:

<asp:Button class="submit google-button" ID="btnLogin" onclick="btnLogin_Click" 

runat="server" Text="Log in" />

except my Search button which is linkButton:

<asp:LinkButton ID="searchLink" runat="server" onclick="searchLink_Click">Search</asp:LinkButton>
1
  • Check which of them made the postback. (the sender parameter). Besides that, take a look at Model View Presenter. It's a good way to work with webforms Commented Sep 5, 2012 at 19:49

1 Answer 1

2

You may use Validation Groups to cause only required text boxes validation on specific button click. And then in event handler to concrete button you may execute specific logic.

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

5 Comments

You could use CausesValidation=false in most similar situations, but here it seems that each button does have it's own set of validations, so groups is indeed the correct solution.
I need more than that, I need also length check and equalsTo check(for the confirm password).
You may check string length with RegularExpressionValidator (e.g ^[\w\s]{1,50}$). For equals you may use CompareValidator (msdn.microsoft.com/en-us/library/…)
One more thing, how can I check for the email, if it is valid.

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.