I'm glad I could help Arpit!
Since you posted your code, I think I should do the same since it might also help other people. I used a different approach I think:
1) This is my markup:
<asp:TextBox ID="txtCity" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
<cc2:AutoCompleteExtraExtender runat="server" ID="aceCity" TargetControlID="txtCity"
BehaviorID="aceCity" ServicePath="" ServiceMethod="GetCities" MinimumPrefixLength="4"
CompletionInterval="1000" EnableCaching="true" CompletionSetCount="15"
SelectedValue='<%# Bind("IdCity") %>' SelectedText='<%# Eval("City") %>'/>
<asp:CustomValidator ID="cvCity" ClientValidationFunction="ValidateAutoComplete" runat="server"
ErrorMessage="You must select a city from the dropdown list" ControlToValidate="txtCity"
SetFocusOnError="true" ValidationGroup="GridO" Value="aceCity" ValidateEmptyText="true"></asp:CustomValidator>
As you can notice, for the validator to work you need to define the extender's BehaviorID, since that's what you'll use to "find" the control using Javascript. Here I'm using a nasty trick to make the validation process easier, and that's defining a Value Property for the Custom Validator. Custom Validators don't have a Value Property, so this one is in reality a custom property that uses a typical property's name (that way the Markup validator doesn't show you an error about an invalid property).
2) And here is the Javascript that you need to use for the Validator to work:
function ValidateAutoComplete(behavior, control)
{
var validator = $find(behavior.attributes['Value'].value);
var value = validator.get_selectedValue();
var text = validator.get_selectedText();
if(value == "-1" || text != control.Value)
control.IsValid = false;
else
control.IsValid = true;
}
When you reference this code in the page and you include the markup I pasted right above it, you'll get yourself a custom validator that checks that an option has been previously selected using the AutoCompleteExtra Extender, and it also checks that the user hasn't changed the text in the TextBox since he last chose an option (this is great for the situations where the user chooses an option and then, before postback occurs, changes the text without selecting any options from the list. If this where to happen, you'd get the right selectedValue, but if you read the TextBox's text, you'd find something completely different to the real selectedText). Of course, this last part is completely optional, and you can simply modify the Javascript if you don't want that to happen.
The main advantage of this method is that you only need to create a Behaviour ID for the Extender, regardless of how the Page gets rendered and how the ID looks in the client.