C# ASP.NET Forms - Client Side Validation using Custom Validator Control 
Author Message
 C# ASP.NET Forms - Client Side Validation using Custom Validator Control

I am creating a Validation example in C# using the Custom Validator control.
When I raise the "ServerValidate" event of the Custom Validator, the
following
can be coded to determine whether the input value is valid:

  private void CustomValidator1_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
  {
   try
   {
    int x = Int32.Parse(Textbox4.Text);
                  if (Textbox4.Text.Length == 4)
     args.IsValid = true;
    else
     args.IsValid = false;
   }
   catch
   {
    args.IsValid = false;
   }
  }

In order to do Client-Side Validation, I am using JavaScript but in the HTML
View,
setting the call to the function in the "ClientValidationFunction" Property
of the
Custom Validator:

   function ccClientValidate1(source, arguments)
  {
             var cc = arguments.Value;

     if(cc.length != 4) {
       arguments.IsValid = false;
                 return;
             }
   else  {
      arguments.IsValid = true;
                return;
  }
  }

I would like to know if there is a way of raising a "Client-Validator" event
in the design/C# Code view and put the client-side validation there. I have
manually set up the
following function, I am not sure what to place in the ???, but this class
needs to contain the property "args" in order to enable the validation.

  public void ClientValidateExample(object source,
System.Web.UI.WebControls.??? args)
  {
   try
   {
    int x = Int32.Parse(Textbox5.Text);
    if (Textbox5.Text.Length == 4)
     args.IsValid = true;
    else
     args.IsValid = false;
   }
   catch
   {
    args.IsValid = false;
   }
  }

Please e-mail me with any thoughts.
Much Appreciated.
PP.



Thu, 21 Oct 2004 19:27:24 GMT  
 C# ASP.NET Forms - Client Side Validation using Custom Validator Control
PP,

    This isn't possible.  The C# code that you are writing, for now (until
IE is changed otherwise), is run completely on the server side.  Because of
this, you will not be able to have access to the components on the server
side in your client side code.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> I am creating a Validation example in C# using the Custom Validator
control.
> When I raise the "ServerValidate" event of the Custom Validator, the
> following
> can be coded to determine whether the input value is valid:

>   private void CustomValidator1_ServerValidate(object source,
> System.Web.UI.WebControls.ServerValidateEventArgs args)
>   {
>    try
>    {
>     int x = Int32.Parse(Textbox4.Text);
>                   if (Textbox4.Text.Length == 4)
>      args.IsValid = true;
>     else
>      args.IsValid = false;
>    }
>    catch
>    {
>     args.IsValid = false;
>    }
>   }

> In order to do Client-Side Validation, I am using JavaScript but in the
HTML
> View,
> setting the call to the function in the "ClientValidationFunction"
Property
> of the
> Custom Validator:

>    function ccClientValidate1(source, arguments)
>   {
>              var cc = arguments.Value;

>      if(cc.length != 4) {
>        arguments.IsValid = false;
>                  return;
>              }
>    else  {
>       arguments.IsValid = true;
>                 return;
>   }
>   }

> I would like to know if there is a way of raising a "Client-Validator"
event
> in the design/C# Code view and put the client-side validation there. I
have
> manually set up the
> following function, I am not sure what to place in the ???, but this class
> needs to contain the property "args" in order to enable the validation.

>   public void ClientValidateExample(object source,
> System.Web.UI.WebControls.??? args)
>   {
>    try
>    {
>     int x = Int32.Parse(Textbox5.Text);
>     if (Textbox5.Text.Length == 4)
>      args.IsValid = true;
>     else
>      args.IsValid = false;
>    }
>    catch
>    {
>     args.IsValid = false;
>    }
>   }

> Please e-mail me with any thoughts.
> Much Appreciated.
> PP.



Fri, 22 Oct 2004 21:54:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Server Side and Client Side Scripting in ASP.NET

2. Client Side Validation preventing client side script from running

3. ASP.NET: adding client-side attributes to webform server control

4. Professional ASP.NET Server Controls - Building Custom Controls with C#

5. Client-side processing in asp.net

6. using validator in custom control

7. Request.Form question in C# ASP.NET

8. client side validation messages

9. ASP.NET user control custom designer question

10. Custom controls in ASP.NET

11. ASP.NET user control custom designer question

12. ASP.NET Server Controls Vs Windows Forms UserControls

 

 
Powered by phpBB® Forum Software