Solved

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

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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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