ASP.NET validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

Can anyone please tell me how to perform validation an a control based on a value in another control. i.e. If control A == "Hello" then perform validation on control B, otherwise don't perform the validation on control
any ideas

Thanks eveeryon

Kevin
 
Hi Kevin,

This depend of your page logic, what I do in a case like this is have a
method in the code behind page which I call before the action I will
perform, in the method I do all the checking I need if it's failed I make
visible a label in the page with the error description, you could even put
the focus in the failing control if you want using Javascript.

then in the handler the first thing I do is check if the validation passed,
if not just return or do what you need.

void ProcessClick(... )
{
if ( !CheckControls() )
return;


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Kevin said:
Hi all,

Can anyone please tell me how to perform validation an a control based on
a value in another control. i.e. If control A == "Hello" then perform
validation on control B, otherwise don't perform the validation on control B
 
On of the solution to do this is to use CustomValidator control

private void controlA_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if ( control A == "Hello" )
{
if (perform validation on the second control is true)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
}

Kevin said:
Hi all,

Can anyone please tell me how to perform validation an a control based on
a value in another control. i.e. If control A == "Hello" then perform
validation on control B, otherwise don't perform the validation on control B
 
Back
Top