Custom Validation

Mayfield2268

Active member
Joined
Feb 24, 2003
Messages
30
Im trying to use custom validation to verify that user input matchs a value in a database.

I have no problem getting it to work with the use of a submit button.

Im wondering if there is a way to get it to work with a control. I have a tab view control and when I click on a different tab I want to be able to validate before it gets redirected to the new page.

Is there a way I can post the form to the server without the use of a submit button?

Thanks
Jason Lee Mayfield
 
If you drop a validation control on to your form you should be able to set the ControlToValidate property to any control that allows validation.

If you dont want to use the submit button, you can always use the TextChanged event and set the AutoPostBack to true, that way if the user changes the value, and clicks outside of the control, itll automatically post back.

<asp:TextBox id="text1" AutoPostBack="true" OnTextChanged="text1_TextChanged" runat="server" />

When the user makes a change to the control and the page is posted back, you can use the Page.IsValid property to see if the control has an error or not and act appropriately.

Something like this maybe?

C#:
void text1_TextChanged(object sender, System.EventArgs e) {
   Page.Validate();
   if (!Page.IsValid)
      // error code.
   }
}

Not sure if thats what you ment or not, but hopefully I at least answered part of your question.
 
Back
Top