I have a ValidatorCalloutExtender which is bound to a customvalidator control. Custom validator calls a javascript function that sends a asynchronous reques to a page method and retrieves the result. Based on that result, error message is show with validator
callout extender. Here is a sample code:
<asp:TextBox ID="TextBoxCode" runat="server" Width="195px"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator6" runat="server"
ControlToValidate="TextBoxCode" Display="None"
ErrorMessage="This code already exists in database.<br/> Please enter another one."
ForeColor="Red"
ValidationGroup="InsertUpdate"
ClientValidationFunction="CheckUniqueness"></asp:CustomValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender14" runat="server"
PopupPosition="Right" TargetControlID="CustomValidator6">
</ajaxToolkit:ValidatorCalloutExtender>
ramsesiitr
Member
149 Points
73 Posts
CustomValidator and ValidatorCalloutExtender with jquery ajax
Aug 15, 2012 07:26 PM|LINK
Hi all,
I have a ValidatorCalloutExtender which is bound to a customvalidator control. Custom validator calls a javascript function that sends a asynchronous reques to a page method and retrieves the result. Based on that result, error message is show with validator callout extender. Here is a sample code:
<asp:TextBox ID="TextBoxCode" runat="server" Width="195px"></asp:TextBox> <asp:CustomValidator ID="CustomValidator6" runat="server" ControlToValidate="TextBoxCode" Display="None" ErrorMessage="This code already exists in database.<br/> Please enter another one." ForeColor="Red" ValidationGroup="InsertUpdate" ClientValidationFunction="CheckUniqueness"></asp:CustomValidator> <ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender14" runat="server" PopupPosition="Right" TargetControlID="CustomValidator6"> </ajaxToolkit:ValidatorCalloutExtender>and the javascript function is:
function CheckUniqueness(source, arguments) { $.ajax({ type: "POST", async: "true", timeout: 500, contentType: "application/json", dataType: "json", url: "ContentManagement.aspx/IsUnique", data: '{"code":"' + arguments.Value + '"}', success: function (result) { //alert(result.d); if (result.d == false) arguments.IsValid = false; else arguments.IsValid = true; } }); }the c# code simply returns false as
[WebMethod] public static bool IsUnique(string code) { return false; }The problem is that argument.IsValid is never assigned and the error message is not shown.
I checked the returned value (alert(result.d)) and it is false as expected. But, why is not the error message shown? Any ideas?
Any help greatly appreciated.
validatorcalloutextender CustomValidator JQuery ajax
chetan.sarod...
All-Star
65749 Points
11148 Posts
Re: CustomValidator and ValidatorCalloutExtender with jquery ajax
Aug 16, 2012 03:29 AM|LINK
http://forums.asp.net/t/1054676.aspx
validatorcalloutextender CustomValidator JQuery ajax
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
ramsesiitr
Member
149 Points
73 Posts
Re: CustomValidator and ValidatorCalloutExtender with jquery ajax
Aug 16, 2012 06:56 AM|LINK
Thanks for reply,
But I am already using the client side javascript code. The only difference is that I am calling a server side function from javascript...
validatorcalloutextender CustomValidator JQuery ajax
Song-Tian - ...
All-Star
43697 Points
4304 Posts
Microsoft
Re: CustomValidator and ValidatorCalloutExtender with jquery ajax
Aug 16, 2012 09:12 AM|LINK
Hi,
Then just use pagemethod or webservice to call server side function from client side.
For webservcie, please refer to: http://msdn.microsoft.com/en-us/library/bb398995(v=VS.90).aspx.
And pagemethod, please refer to: http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx.
Feedback to us
Develop and promote your apps in Windows Store
ramsesiitr
Member
149 Points
73 Posts
Re: CustomValidator and ValidatorCalloutExtender with jquery ajax
Aug 17, 2012 03:32 PM|LINK
My mistake...
I found the error. The jquery function should look like this. Apperantly, I cannot change the IsValid value from success function of ajax.
function CheckUniqueness(source, arguments) { var response; $.ajax({ type: "POST", async: "true", timeout: 500, contentType: "application/json", dataType: "json", url: "ContentManagement.aspx/IsUnique", data: '{"code":"' + arguments.Value + '"}', success: function (result) { response=result.d } }); arguments.IsValid=response; }Sorry for kind of spamming.
validatorcalloutextender CustomValidator JQuery ajax
kanaksanket
Member
15 Points
28 Posts
Re: CustomValidator and ValidatorCalloutExtender with jquery ajax
Oct 01, 2012 05:51 AM|LINK
i am using same code but not getting an answer
function validateLength(source, arguments) { var response; $.ajax({ type: "POST", async: "true", timeout: 500, contentType: "application/json", dataType: "json", url: "WebService.asmx/checkemployee", success: function(result) { response = result.d alert(response); } }); alert(response); arguments.IsValid = response; }om success responce it shows responce value true
but in outside it dont shows the any value it shows it as undefined
reply