开发者

Asp.Net web form validation with jquery Ajax

I want to kn开发者_开发百科ow the best simple tutorial for asp.net web form validation with Jquery (Ajax) not plugin.I want to develop the ajax form with jquery.

I have a registeration form.When I submit the form,I want to call asp.net validation method by jquery $.ajax . I want to validate the form field with server side validation. I don't want to use jquery form validation plugin.


If you want to validate on server-side you should use, for example, asp.net web-service. If you want to create it just add .asmx file in your solution.

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    [WebMethod]
    public bool ValidateDate(string value)
    {
        bool isValide =true;
        //Validation code
        return isValide
    }
}

After creating web-service you can send request to it, using $.ajax

for example, like this (I like to use JSON): where webserviceName is name of your .asmx file and function is name of web-service method you need.

 $.ajax(
{
    type: "POST",
    url: webserviceName + functionName,
    contentType: "application/x-www-form-urlencoded; windows-1251;",
    dataType: json,
    data: parameters,
    success: callbackFunction,
    error: errorCallbackFunction
});

See example on this page - http://msdn.microsoft.com/en-us/library/bb515101.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜