0

my situation is like this thread :
ASP.NET Custom Validator + WebMethod + jQuery
my aspx codes :

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="True">
<asp:TextBox ID="TextBox" runat="server" Width="170px" ValidationGroup="A" CssClass="txt"
            TextMode="Password"></asp:TextBox>
 <asp:CustomValidator ID="cvPass" runat="server" Display="Dynamic" ControlToValidate="TextBox"
            ValidationGroup="A" ClientValidationFunction="CheckPass">
            invalid
</asp:CustomValidator>

jquery:

    function CheckPass(source, args) {
        alert('asd');
        $.ajax({
            type: "POST",
            async: false,
            timeout: 500,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            url: "Default.aspx/CheckPassword",
            data: '{"Value":"' + args.Value + '"}',
            success: function (result) {
                alert('a');
                args.IsValid = result.d;
            }
        });
    }

code behind (c#):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Text;
using System.Net.Mail;

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

        [WebMethod]
        [ScriptMethod]
        public static bool CheckPassword(string pass)
        {
             return false;
        }
    }
}

as you see i want to check password using custom validator in ajax mode(using jquery).
but i do n't know why $.ajax does not work for me at all.
there is no error and nothing happens and always have postback.
should i add an specific library other that jquery?
i am using visual studio 2010 + .Net 4.
what is the problem and how can i fix it?

thanks in advance

4
  • Does the alert fire? Are you including any other javascript libraries besides jquery? Have you looked at the response of the post in a tool like firebug? Commented Jun 28, 2012 at 23:21
  • i did n't see alert('a'); at all. working on firebug! Commented Jun 28, 2012 at 23:27
  • Sorry, I was referring to the alert('asd') when I said alert. Just was confirming that your js function was actually getting called. Commented Jun 28, 2012 at 23:38
  • there is no problem about alert('asd'); mean if fires. please see this thread -> stackoverflow.com/questions/8890554/… Commented Jun 28, 2012 at 23:48

1 Answer 1

4

From the code you've showed it should work but there are potentially some other areas of your code that could be contributing to your problems.

Some areas I'd investigate:

  • You're using a validation group for your text box and custom validator. Does the control that triggers postback also include the ValidationGroup="A" attribute?
  • When calling the Web Method you're passing in '{"Value":"' + args.Value + '"}', as your data to the method call. I think you need to change "Value" to "pass" to match the Web Method parameter name.
  • I haven't worked much with Telerik controls. Perhaps the RadScriptManager is intercepting events in some way?

I'd recommend creating a version of your page that just uses the bare minimum of code to prove whether what you're trying to do works or not: a simple page, with a text box control, the custom validator, the jQuery code and the web method in the code behind.

Hopefully that will help you uncover any problems.

Sign up to request clarification or add additional context in comments.

1 Comment

really thanks for nice attention. solved-> "Value" to "pass". so there is no problem about RadScriptManager. also the control that triggers postback has ValidationGroup="A".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.