views:

76

answers:

2

Short description of the page: user searches for an account (first form is to search for an account), account information gets displayed below and you can make changes to that account (second form).

I currently have this feature in only one form, but I am running into problems when I try to validate (since pressing any of the two buttons will try to validate all fields although that is not right, since if you are searching you don't need to fill out the other fields to edit). Also, when I press enter in any of the text boxes the search button is clicked, how can I associate a text box to a particular button.

+2  A: 

What about using the CausesValidation attribute on your search button.

or you could use a custom validator like this

<asp:TextBox ID="TestBox" runat="server"></asp:TextBox>
<asp:CustomValidator ErrorMessage="Not" ID="CustomValidator1" Enabled="true"    
   ControlToValidate="TestBox"
   runat="server"></asp:CustomValidator>
<asp:Button ID="myButton" CausesValidation="true" OnClick="TestClick" runat="server" />

Then have your button have an onclick command like this

public void TestClick(object sender, EventArgs e)
{
    if(this.TestBox.Text == "me") this.CustomValidator1.IsValid = false;
    return;
}
Mark Dickinson
Obviously set this false, and it should sort your problem.
Mark Dickinson
+4  A: 

To only validate certain form fields you can add a common ValidationGroup to all validators you require validating within that group and also the button that submits them. Alternatively, set the CausesValidation property of any button(s) you don't want to trigger validation when pressed.

You can also specify the default button within asp:panel. This controls what button is fired when you hit enter within the panel. So, wrap a panel around your form and specify the button in the panel like so:

<asp:Panel ID="PanelForm" runat="Server" DefaultButton="ButtonSubmit">

    <!-- Form fields go here... -->

    <asp:Button ID="ButtonSubmit" runat="Server" Text="Submit" />

</asp:Panel>
Dan Diplo
Forgot all about default button +1 :)
Mark Dickinson
I forgot to mention I can't use this since the version of ASP.NET I am using (1.1) does not support it.
Alejandro