user43553
user43553

Reputation: 65

Call validate function along with submit data function on button click

I want to validate a code, and if it is correct than send the data on page to DB.

Here are the functions:

ValidateCode(object send, EventArgs e)
{ logic here}

And the submit button code:

Register_Clicked(object sen, EventArgs e)

So within the Register click I want to fire the ValidateCode function and if it is correct than only save data.

Upvotes: 1

Views: 105

Answers (1)

ek9
ek9

Reputation: 3442

First, make sure your ValidateCode() function returns a boolean value (true if validation is passed; false otherwise):

ValidateCode(object send, EventArgs e)
{ 
    // logic here

    // return boolean value
    if (passed) {
        return true;
    }

    return false;
}

Then you can add this in your register_clicked function:

 Register_Clicked(object send, EventArgs e)
 {
     if (ValidateCode(send, e)) {
         // validation passed code
     } else {
         // validation failed code
     }
 }

Upvotes: 1

Related Questions