How to force validation of UserControl?Validate decimal numbers in JavaScript - IsNumeric()How to validate an email address in JavaScript?How do I enumerate an enum in C#?Cross-thread operation not valid: Control accessed from a thread other than the thread it was created onHow to validate an email address using a regular expression?How do I make a textbox that only accepts numbers?expose and raise event of a child control in a usercontrol in c#How to force validation to show on UserControlUserControl Validation in c#UserControl TextBox Validation in C#?

How can I add custom success page

How could a lack of term limits lead to a "dictatorship?"

Need help identifying/translating a plaque in Tangier, Morocco

Ideas for 3rd eye abilities

"listening to me about as much as you're listening to this pole here"

Could a US political party gain complete control over the government by removing checks & balances?

What are the advantages and disadvantages of running one shots compared to campaigns?

Is there a familial term for apples and pears?

What is the meaning of "of trouble" in the following sentence?

I see my dog run

Is Social Media Science Fiction?

Are cabin dividers used to "hide" the flex of the airplane?

Domain expired, GoDaddy holds it and is asking more money

Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?

Information to fellow intern about hiring?

A poker game description that does not feel gimmicky

How to move the player while also allowing forces to affect it

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

How can I fix this gap between bookcases I made?

Are objects structures and/or vice versa?

Is a vector space a subspace?

Where to refill my bottle in India?

What is the command to reset a PC without deleting any files

Is ipsum/ipsa/ipse a third person pronoun, or can it serve other functions?



How to force validation of UserControl?


Validate decimal numbers in JavaScript - IsNumeric()How to validate an email address in JavaScript?How do I enumerate an enum in C#?Cross-thread operation not valid: Control accessed from a thread other than the thread it was created onHow to validate an email address using a regular expression?How do I make a textbox that only accepts numbers?expose and raise event of a child control in a usercontrol in c#How to force validation to show on UserControlUserControl Validation in c#UserControl TextBox Validation in C#?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















Validations for my textbox controls work normally/as expected. However, for my created UserControl, also containing a textbox (which also contains other controls as well), it's not always validated, except when the user manually selects/focuses another control, which will of course fire the Validating event.



Now, I've found from searches about Form.ValidateChildren() (which works btw), but this method validates all children as described in the documentation, which is not the ideal solution to a form with many controls, as opposed to only validating the single control in question.



Additional info:



  1. I use ErrorProvider to show errors - I need to consider the position
    of the icon in the case of my UserControl (which again, contains
    multiple controls inside).


  2. Validating and Validated events are performed on my UserControl, not the TextBox inside it. Both events are on the form where the usercontrol is used.

  3. The Text property of the TextBox inside my UserControl is modified
    internally (inside my UserControl class)

`



//some code inside usercontrol
private void SomeMethod()

...
textBox.Text = ...;
ParentForm.ValidateChildren(); // works but does this on all controls which is not the ideal operation, which is to perform validation only on this usercontrol



`



With the above-mentioned info, when I modify the Text property manually, the Validating event is, as expected on the design, not raised since UserControl.TextBox != UserControl. It's not an option for me to perform validation on the UserControl.TextBox instead of the UserControl.



With all that explained, how should I manually/forcefully trigger the validation only for the UserControl, when UserControl.TextBox.Text is modified, without resorting to Form.ValidateChildren which targets all of the form controls? Or is it not possible?










share|improve this question
























  • UserControls have a ValidateChildren() method as well.

    – Jimi
    Mar 8 at 7:57











  • As described in the question, the control I need to validate is the UserControl itself, not its children.

    – Michael Balser
    Mar 8 at 8:07











  • Call UserControl.Validate() then. If the UC has unvalidated controls, overriding OnValidating will intercept it. No matter if AutoValidate is disabled.

    – Jimi
    Mar 8 at 8:34












  • Tried calling Validate() for UserControl, did not work though. I wonder what is further needed for this to work.

    – Michael Balser
    Mar 8 at 8:38






  • 1





    I don't know what did not work means. Did you change something in some child control? If you don't change anything, OnValidating is not called.

    – Jimi
    Mar 8 at 8:40

















2















Validations for my textbox controls work normally/as expected. However, for my created UserControl, also containing a textbox (which also contains other controls as well), it's not always validated, except when the user manually selects/focuses another control, which will of course fire the Validating event.



Now, I've found from searches about Form.ValidateChildren() (which works btw), but this method validates all children as described in the documentation, which is not the ideal solution to a form with many controls, as opposed to only validating the single control in question.



Additional info:



  1. I use ErrorProvider to show errors - I need to consider the position
    of the icon in the case of my UserControl (which again, contains
    multiple controls inside).


  2. Validating and Validated events are performed on my UserControl, not the TextBox inside it. Both events are on the form where the usercontrol is used.

  3. The Text property of the TextBox inside my UserControl is modified
    internally (inside my UserControl class)

`



//some code inside usercontrol
private void SomeMethod()

...
textBox.Text = ...;
ParentForm.ValidateChildren(); // works but does this on all controls which is not the ideal operation, which is to perform validation only on this usercontrol



`



With the above-mentioned info, when I modify the Text property manually, the Validating event is, as expected on the design, not raised since UserControl.TextBox != UserControl. It's not an option for me to perform validation on the UserControl.TextBox instead of the UserControl.



With all that explained, how should I manually/forcefully trigger the validation only for the UserControl, when UserControl.TextBox.Text is modified, without resorting to Form.ValidateChildren which targets all of the form controls? Or is it not possible?










share|improve this question
























  • UserControls have a ValidateChildren() method as well.

    – Jimi
    Mar 8 at 7:57











  • As described in the question, the control I need to validate is the UserControl itself, not its children.

    – Michael Balser
    Mar 8 at 8:07











  • Call UserControl.Validate() then. If the UC has unvalidated controls, overriding OnValidating will intercept it. No matter if AutoValidate is disabled.

    – Jimi
    Mar 8 at 8:34












  • Tried calling Validate() for UserControl, did not work though. I wonder what is further needed for this to work.

    – Michael Balser
    Mar 8 at 8:38






  • 1





    I don't know what did not work means. Did you change something in some child control? If you don't change anything, OnValidating is not called.

    – Jimi
    Mar 8 at 8:40













2












2








2


1






Validations for my textbox controls work normally/as expected. However, for my created UserControl, also containing a textbox (which also contains other controls as well), it's not always validated, except when the user manually selects/focuses another control, which will of course fire the Validating event.



Now, I've found from searches about Form.ValidateChildren() (which works btw), but this method validates all children as described in the documentation, which is not the ideal solution to a form with many controls, as opposed to only validating the single control in question.



Additional info:



  1. I use ErrorProvider to show errors - I need to consider the position
    of the icon in the case of my UserControl (which again, contains
    multiple controls inside).


  2. Validating and Validated events are performed on my UserControl, not the TextBox inside it. Both events are on the form where the usercontrol is used.

  3. The Text property of the TextBox inside my UserControl is modified
    internally (inside my UserControl class)

`



//some code inside usercontrol
private void SomeMethod()

...
textBox.Text = ...;
ParentForm.ValidateChildren(); // works but does this on all controls which is not the ideal operation, which is to perform validation only on this usercontrol



`



With the above-mentioned info, when I modify the Text property manually, the Validating event is, as expected on the design, not raised since UserControl.TextBox != UserControl. It's not an option for me to perform validation on the UserControl.TextBox instead of the UserControl.



With all that explained, how should I manually/forcefully trigger the validation only for the UserControl, when UserControl.TextBox.Text is modified, without resorting to Form.ValidateChildren which targets all of the form controls? Or is it not possible?










share|improve this question
















Validations for my textbox controls work normally/as expected. However, for my created UserControl, also containing a textbox (which also contains other controls as well), it's not always validated, except when the user manually selects/focuses another control, which will of course fire the Validating event.



Now, I've found from searches about Form.ValidateChildren() (which works btw), but this method validates all children as described in the documentation, which is not the ideal solution to a form with many controls, as opposed to only validating the single control in question.



Additional info:



  1. I use ErrorProvider to show errors - I need to consider the position
    of the icon in the case of my UserControl (which again, contains
    multiple controls inside).


  2. Validating and Validated events are performed on my UserControl, not the TextBox inside it. Both events are on the form where the usercontrol is used.

  3. The Text property of the TextBox inside my UserControl is modified
    internally (inside my UserControl class)

`



//some code inside usercontrol
private void SomeMethod()

...
textBox.Text = ...;
ParentForm.ValidateChildren(); // works but does this on all controls which is not the ideal operation, which is to perform validation only on this usercontrol



`



With the above-mentioned info, when I modify the Text property manually, the Validating event is, as expected on the design, not raised since UserControl.TextBox != UserControl. It's not an option for me to perform validation on the UserControl.TextBox instead of the UserControl.



With all that explained, how should I manually/forcefully trigger the validation only for the UserControl, when UserControl.TextBox.Text is modified, without resorting to Form.ValidateChildren which targets all of the form controls? Or is it not possible?







c# winforms validation user-controls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 11 at 0:31







Michael Balser

















asked Mar 8 at 7:13









Michael BalserMichael Balser

134




134












  • UserControls have a ValidateChildren() method as well.

    – Jimi
    Mar 8 at 7:57











  • As described in the question, the control I need to validate is the UserControl itself, not its children.

    – Michael Balser
    Mar 8 at 8:07











  • Call UserControl.Validate() then. If the UC has unvalidated controls, overriding OnValidating will intercept it. No matter if AutoValidate is disabled.

    – Jimi
    Mar 8 at 8:34












  • Tried calling Validate() for UserControl, did not work though. I wonder what is further needed for this to work.

    – Michael Balser
    Mar 8 at 8:38






  • 1





    I don't know what did not work means. Did you change something in some child control? If you don't change anything, OnValidating is not called.

    – Jimi
    Mar 8 at 8:40

















  • UserControls have a ValidateChildren() method as well.

    – Jimi
    Mar 8 at 7:57











  • As described in the question, the control I need to validate is the UserControl itself, not its children.

    – Michael Balser
    Mar 8 at 8:07











  • Call UserControl.Validate() then. If the UC has unvalidated controls, overriding OnValidating will intercept it. No matter if AutoValidate is disabled.

    – Jimi
    Mar 8 at 8:34












  • Tried calling Validate() for UserControl, did not work though. I wonder what is further needed for this to work.

    – Michael Balser
    Mar 8 at 8:38






  • 1





    I don't know what did not work means. Did you change something in some child control? If you don't change anything, OnValidating is not called.

    – Jimi
    Mar 8 at 8:40
















UserControls have a ValidateChildren() method as well.

– Jimi
Mar 8 at 7:57





UserControls have a ValidateChildren() method as well.

– Jimi
Mar 8 at 7:57













As described in the question, the control I need to validate is the UserControl itself, not its children.

– Michael Balser
Mar 8 at 8:07





As described in the question, the control I need to validate is the UserControl itself, not its children.

– Michael Balser
Mar 8 at 8:07













Call UserControl.Validate() then. If the UC has unvalidated controls, overriding OnValidating will intercept it. No matter if AutoValidate is disabled.

– Jimi
Mar 8 at 8:34






Call UserControl.Validate() then. If the UC has unvalidated controls, overriding OnValidating will intercept it. No matter if AutoValidate is disabled.

– Jimi
Mar 8 at 8:34














Tried calling Validate() for UserControl, did not work though. I wonder what is further needed for this to work.

– Michael Balser
Mar 8 at 8:38





Tried calling Validate() for UserControl, did not work though. I wonder what is further needed for this to work.

– Michael Balser
Mar 8 at 8:38




1




1





I don't know what did not work means. Did you change something in some child control? If you don't change anything, OnValidating is not called.

– Jimi
Mar 8 at 8:40





I don't know what did not work means. Did you change something in some child control? If you don't change anything, OnValidating is not called.

– Jimi
Mar 8 at 8:40












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058410%2fhow-to-force-validation-of-usercontrol%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058410%2fhow-to-force-validation-of-usercontrol%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved