Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:44:02+00:00 2026-06-10T02:44:02+00:00

Background: I am new to MVP and just coding my first winform application using

  • 0

Background:
I am new to MVP and just coding my first winform application using Model View Presenter
Question:
I have been browsing for best practices on how to write user input validation code for windows controls (e.g TextBox etc) and where to put that code in winforms application using Model View Presenter desing pattern but still confused.
Let me explain
Suppose I have some TextBox controls on my form, which accept inputs like Name, Phone, email, zip etc. Normally I would call different methods like validateName(), validatePhone(), validateEmail() and validateZip() then in each of these methods I would definitely have to check that the input provided by the user in not empty like

    if(txtName.Text.Length == 0)
   {
      errorMessage = "Name is required.";
         return false;
   }

   if(txtEmail.Text.Length == 0)
   {
      errorMessage = "e-mail address is required.";
         return false;
   }

That smells like code repetition and I think there must be a better and efficient way to check whether the text is not null (may be by looping through all textbox controls).

So, What I am thinking is to have a CommonMethods class containing common methods like CheckifTextEmply(), CheckifNumber() etc and use this class throughout all my forms since these is common functionality and can be used by other TextBox controls on other forms in the project.
Now can you please tell me if
1. Is this the right approach, if not then how should I approach this issue
2. If right, where should I put the CommonMethods class (code) in Model View Presenter design.

Regards,
ZB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:44:04+00:00Added an answer on June 10, 2026 at 2:44 am

    Looks a bit old post. Try creating a method which takes control as an argument and then try to validate it.

    bool validate(TextBox txt)
    {
        return string.IsNUllOrEmpty(txt.Text);
    }
    

    you can also try taking a params[] argument to take multiple controls and validate them.

    Regarding the error messages, instead of “Name is required” if you go for “required field” message, it will make the job easier. But if not, try creating dictionary of control and bool, pass false if the validation fails and take action according to it.

    I know the answer is not very descriptive, but right now, I am a bit busy so cant take much time to explain this. Let me know if it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Story: I am developing a GWT application, using the standard MVP design pattern,
I'm pretty new to coding and I am currently using a background image for
I'm trying to create a new spinner background using a 9 patch picture. I've
Background: i'm using InstantRails 2.0 I wanted to add a new column to an
I'm relative new to C++ and my background is in Java. I have to
So i have one class which starts a new class in a new background
I have image background.jpg as the background. Every 10s, how to load a new
I'm fairly new to Android and have been toying around with Canvas. I'm attempting
I have three nested grids where first two of them has background images with
I just wrote a Background class for a new project. The background is basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.