Using multiple conditional statements for individual Controls and putting conditional statements in Public Methods
<p>I am trying to validate multiple fields/Controls based on individual conditions. The issue is I have individual labels that indicate an error based on the specific control rather than a message box; is there a more efficient way to do this?</p>

<p><strong>Here is the code:</strong></p>

<pre><code>if (txtPhone. Text. Length &lt;= 0) 
{ 
lblPhoneRequired.Visible = true; 
} 
else 
{ 
lblPhoneRequired.Visible = false; 
}

if (txtName. Text. Length &lt;= 0) 
{ 
lblNameRequired. Visible = true; 
} 
else 
{ 
lblNameRequired. Visible = false; 
}
</code></pre>

<p>Finally I tried wrapping this into a Public method like this:</p>

<pre><code>public void validation() {
if (txtPhone. Text. Length &lt;= 0)
{ 
lblPhoneRequired.Visible = true; 
} 
else 
{ 
lblPhoneRequired.Visible = false; 
}

if (txtName. Text. Length &lt;= 0) 
{ 
lblNameRequired. Visible = true; 
} 
else 
{ 
lblNameRequired. Visible = false; 
}
}
</code></pre>

<p>Then calling the method in a button click event but it does not work.</p>

<pre><code>private void btnSample_Click(object sender, EventArgs e) 
validation(); 
}
</code></pre>

<p>The is new territory so please bear with my ignorance:</p>

<p>Guy</p>
