Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-15
4
Medium Priority
?
167 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 750 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 750 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

722 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