Solved

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

Posted on 2008-10-15
4
164 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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