OK, I think we are getting somewhere. The code you kindly provided now compiles and I see the ValidatorCalloutExtender. For some reason, I had to pull the items out of the Update panel (?). I do have some bugs however (again, probably due to my translation errors).
When I first load the page, and I type something other than "junnark", when I tab off the textbox, the callout is displayed correctly. However, if I DO enter "junnark", the callout is displayed anyway. If I set a breakpoint in the RaiseCallbackEvent handler, this is what I see: As soon as I enter "junnark" and tab off the field, I see the callout popup, then the breakpoint comes up and as I step through the code, it sets the callBackResult to "Valid". But I think this is "too late", as the callout has already been displayed (?).
Also, if I enter "junnark", press the button, and then change the value of the textbox to some other value, the callout is NOT displayed and I get an "Object expected" error from the page itself.
I'm sorry to keep bugging you, but I think I am really close and I would really appreciate your continued feedback. My complete code is posted below.
Thank you again!
Partial Public Class _Default
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler
Dim callBackResult As String = Nothing
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
' create a call back reference method and then
Dim callBackReference As String = Page.ClientScript.GetCallbackEventReference(Me, "arg", "CallBackEventReference", "context")
Dim yourCallBackScript As String = "function YourCallBackMethod(arg, context) { " + callBackReference + "; }"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "YourCallBackMethod", yourCallBackScript, True)
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
' ICallbackEventHandler Members
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return callBackResult
End Function
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
If eventArgument = "junnark" Then
callBackResult = "Valid"
End If
End Sub
End Class <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="ValidationTest._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>
<!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>Using ValidatorCallout Extender with a CustomValidator Control</title>
<script language="javascript" type="text/javascript">
var resultOfTheCallBack;
function ValidateTextBox(sender, args)
{
var textBoxValue = document.getElementById('TextBox1').value;
// call server callback method passing the value in your textbox
YourCallBackMethod(textBoxValue);
if(resultOfTheCallBack == 'Valid')
args.IsValid = true;
else
args.IsValid = false;
}
function CallBackEventReference(result, context)
{
resultOfTheCallBack = result;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate> <br />
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
Text="Button" OnClick="Button1_Click" />
<asp:CustomValidator ID="CustomValidator1"
ControlToValidate="TextBox1" Display="None" runat="server"
ErrorMessage="b><br/><br/>This is the text in your Validator Callout Extender error.<br/>"
ClientValidationFunction="ValidateTextBox">
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1"
TargetControlID="CustomValidator1" runat="server" />
</div>
</form>
</body>
</html>