Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: End event 1

Status
Not open for further replies.

JBaileys

Technical User
Jun 23, 2003
244
US

I have a button and on the click event I do some error checking. If the error checking fails, I send a messagebox and I want to "end" the click event. What is the command to complete this?

I have tried return and break with no luck.
 
I'm not 100% sure I understand...After you send the checkbox, what do you want to do? If you're returning the user to a page (form?) to repopulate field X, transfer control back to there and prompt them to fill the box with valid data. I guess maybe seeing your code would help..
hth

All hail the INTERWEB!
 

Not actually working with a checkbox, rather the click event of a button.

And I am not repopulating any fields - I simply wanted the events in the click event to end.

The click event of the button does the error checking - if there are no errors then the app calls a function - therefore no longer in the if conditional logic.

I was looking for a keyword like terminate or close to no longer execute events in the click event.

The original end result would be the user receiving an error and then kicking out of the click event as if it never occurred.
 
Sorry..I must have been doing somethin else when I posted.."checkbox" was supposed to be somethin like "form element"

What are you validating (ex: textbox?) what are you validating for? I'm not sure how you're going about validating....You need to do somethin like
Code:
private void button1_Click(object sender, System.EventArgs e)
 {
//if your validation function returns true to indicate its valid data.  Call the next function in your program.
//else validation returns false so run some other logic
 }

You don't cease processing of the event, you just call in the next piece of code you need to execute if the data has been validated.

And wouldnt you want the user gettin kicked out of the click event so they could then enter valid data and click the button again (to run your validation again)
You should really post some code it would make this a lot easier.

All hail the INTERWEB!
 

Yes, the validation is on a text box. The user is entering in a couple fields and we are verifying the length of the text boxes.

I did set up the code somewhat like your example. So - we can use your "code" as an illustration. My concern is if my form had more controls with additional validation that the if then logic would get very nested as some error messages are dependent on multiple controls and their respective values. The code would show if...elseif... elseif... elseif... elseif etc.

My original plan was to execute the conditional if - if validation was invalid - produce a message / "error" and "exit the click event".
 
Well then I guess the question really comes down to what it is you are validating for. There are a ton of very handy validation controls built right into .net that simplify the formally tedious process of validation significantly, to say the least. Furthermore, if none of the existing validation controls have the ability validate for what you need to validate for, you can create your own.

Since i'm not really sure what you're validating for here is a link to the basic .net validation controls...


All hail the INTERWEB!
 
i may be being a bit dense, but my guess at what you mean is this.

Code:
if errorthrown then stopevent

which would be in c#

Code:
try
{
  // function that throws an exception goes here
}
catch ( Exception ex )
{
  MessageBox.Show(this, ex.Message);
  return;
}

//more code goes here: not reached if error thrown

the return statement will stop the event dead in its tracks.

regards,


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top