Solved

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now