Solved

How to validate two different text boxe's in ASP.NET 2.0

Posted on 2008-10-15
4
162 Views
Last Modified: 2013-11-07
Hello,

 I need to validate two text boxe's , where one field is ID and other is Emp Code.Where in the form user has to input data in one of them or both.But cannot skip both., I need validation in ASP.NET 2.0 without Javascript.
I need if it works with Custom validator, how can I do that.

Thanks
0
Comment
Question by:DevIndian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22727874
0
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 250 total points
ID: 22728442
"I need validation in ASP.NET 2.0 without Javascript."

Assuming you have some king of submit button in it's click event handler you could do something like this:
if (string.IsNullOrEmpty(textboxID.Text.Trim()) && string.IsNullOrEmpty(textboxEmpCode.Text.Trim()))
{
   // notify user about wrong input
}
else
{
   // validation passed, proceed as usually
}

Open in new window

0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22728445
...you have some kind of ...

sorry for typos :)
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 250 total points
ID: 22730558
use custom validator control and provide the event for OnServerValidate

On the server side for that custom validator control check for the existance of value like this

if (Page.IsValid)
{
    if (txtBox_1.Text.Trim() == string.Empty && txtBox_2.Text.Trim() == string.Empty) //if both are empty
    {
        args.IsValid = false;
        return;
    }
    args.IsValid = true;
    return;
}
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question