ValidatorCalloutExtender + CustomValidator – It´s possible?

WHERE´S THE ValidatorCalloutExtender?

Where´s ValidatorCalloutExtender? 

 

Portuguese Question
—————————————————-
Estou tentando chamar um ValidatorCalloutExtender a partir de um CustomValidator, alguém aqui já fez isso? Isso é possível? Pois no meu exemplo abaixo isso não funciona.

 

English Question
—————————————————-
I can try to call ValidatorCalloutExtender from a CustomValidator, but it´s not work. It´s possíble? My example doesn´t work.
PLEASE HELP ME!

——————————————————————————————————————————————————————————————- 
teste.aspx 
——————————————————————————————————————————————————————————————- 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="teste.aspx.cs" Inherits="teste" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


        <asp:CustomValidator ID="CustomValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="weadsasdsa" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
        <ajaxToolkit:ValidatorCalloutExtender ID="ceUsuarioNome" TargetControlID="CustomValidator1" runat="server"></ajaxToolkit:ValidatorCalloutExtender>


        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

 

——————————————————————————————————————————————————————————————- 
teste.aspx.cs
——————————————————————————————————————————————————————————————- 

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class teste : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if(TextBox1.Text == "janis"){
            args.IsValid = true;
        }else{
            args.IsValid = false;
        }
    }
}

 

 

I believe, from
looking at the ValidatorCallout known issues
, that it only works on CustomValidators
with client-side validation (i.e., JavaScript).  Here’s the part of the sentence:

"…will only work for custom validators which utilize client-side validation."

Can you show some exemple code??
I´m having this problem too.
[:(]

Tks…
See yaa!

From what I’ve seen, you cannot use the ValidatorCalloutExtender when the CustomValidator is using a server side validation.  In this case the solution is relatively simple.  Instead of using a CustomValidator, try using a RegularExpressionValidator.  I’ve
tested the following at it will work with ValidatorCalloutExtender without a postback. 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" Title="Untitled Page" StylesheetTheme="SkinFile" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="Button" />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                    ControlToValidate="TextBox1" Display="None" ErrorMessage="weadsasdsa"
                    ValidationExpression="janis" />
                <ajaxToolkit:ValidatorCalloutExtender ID="ceUsuarioNome"
                    TargetControlID="RegularExpressionValidator1" runat="server" />
   

            </div>
        </form>
    </body>
</html>

  

If you still want to use a CustomValidator, then create a ClientValidationFunction instead of a server side function.  The following demonstrates an example of this.

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" Title="Untitled Page" StylesheetTheme="SkinFile" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
           function ClientValidate(source, clientside_arguments)
           {
              if (clientside_arguments.Value == "janis" )
              {
                 clientside_arguments.IsValid = true;
              }
              else { clientside_arguments.IsValid = false; }
           }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" Text="Button" />
                <asp:CustomValidator ID="CustomValidator1" runat="server" Display="None" ErrorMessage="Error"
                    ControlToValidate="TextBox1" ClientValidationFunction="ClientValidate" />
                <ajaxToolkit:ValidatorCalloutExtender ID="ceUsuarioNome" TargetControlID="CustomValidator1"
                    runat="server" />
            </div>
        </form>
    </body>
</html>

  

or in your custom validator place a field to validate it could be any text box but validate callout needs something ,

<asp:CustomValidator
ID="RCVlen2"
ControlToValidate="wid3"
runat="server"
ErrorMessage="Adjust
end widths"
ClientValidationFunction="ValidateCheckBox"
Display="None"></asp:CustomValidator>

<asp:ValidatorCalloutExtender
ID="vcblen2C2"
runat="server"
TargetControlID="RCVlen2"
CssClass="vcall">

 

Leave a Reply