locked
Textbox validation RRS feed

  • Question

  • Hai

    In our project  if we press 'Alt S'  then save will fire.But our problem is when we change somthing in the textbox ,then if validation falil then also save button coding is firing.How we will block that.

    For Example

    private void txtStoneWt_Validating(object sender, CancelEventArgs e)

    {

     if (!stoneWtValidate()) { return; }

    }

    Now i press Alt-S after changing the value of txtstonewt, then stonewt validation fired and validation failed.I gave "return" then also the "Save Button" coding is executing.

    Please some one help me

    Saturday, May 24, 2014 1:19 PM

Answers

  • You should put any validation logic in a method (stoneWtValidate() ? ) and then call this method both from the Validating event handler and from the event handler that gets invoked when you are pressing ALT+S. If the method returns false, you should not save but perhaps displaying a MessageBox saying that the validation has failed or something. Anyway, you need to call the validation method in the event handler that gets invoked when the ALT+S keyboard combination is pressed.

    Please share your code for further help.

    • Proposed as answer by Marvin_Guo Wednesday, May 28, 2014 2:30 AM
    • Marked as answer by Marvin_Guo Friday, May 30, 2014 9:32 AM
    Saturday, May 24, 2014 1:34 PM