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>
Andreas Lymbouras
  • 1,025
  • 17
  • 26
  • 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 – Thiago Custodio Sep 05 '12 at 19:49

1 Answers1

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.

petro.sidlovskyy
  • 5,075
  • 1
  • 25
  • 29
  • 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. – Servy Sep 05 '12 at 19:51
  • I need more than that, I need also length check and equalsTo check(for the confirm password). – Andreas Lymbouras Sep 05 '12 at 22:22
  • You may check string length with RegularExpressionValidator (e.g ^[\w\s]{1,50}$). For equals you may use CompareValidator (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.comparevalidator.aspx) – petro.sidlovskyy Sep 05 '12 at 22:27
  • One more thing, how can I check for the email, if it is valid. – Andreas Lymbouras Sep 06 '12 at 06:50
  • 1
    Please look here http://stackoverflow.com/questions/1710505/asp-net-email-validator-regex – petro.sidlovskyy Sep 06 '12 at 06:53