c# - Set CauseValidation to false but not working -


i have validating event.

    private void employeeidtextbox_validating(object sender, canceleventargs e)     {          if (employeeidtextbox.text == "")         {             messagebox.show("please enter employeeid.", "invalid employeeid");         }      } 

and set cancelbutton causevalidation false when hit cancelbutton messagebox still shows.

you need set causesvalidation property of controls in hierarchy of cancel button false.

for example: form1 contains panel1 , panel1 contains cancel button. need set causesvalidation property of form1, panel1 , cancel button false.

causesvalidation property of control class. read more here

the control allows fire validating event if causesvalidation true default value.

if controls in hierarchy have causesvalidation true , receive focus before u click on cancel button, validating event fired.

to avoid disabling everywhere controls in panel1, should use separate panel or none cancel button.

hope helps.

edit: checked @ end. whichever control gains focus while moving cancel button should have causesvalidation false.

set causesvalidation false hierarchy of textbox except textbox itself.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -