.NET Daily

Access public methods from code-behind with jQuery

Introduction

Darius

Darius

Darius Dumitrescu is a creative Senior CMS Consultant with in depth .NET knowledge, focused on Web Development and Architecture Design.


LATEST POSTS

My View of a JIRA Workflow for Web Development 17th April, 2018

How To Solve: SQL Server detected a logical consistency-based I/O error: invalid protection option. 19th March, 2018

ASP.net

Access public methods from code-behind with jQuery

Posted on .

Have you ever wanted to check the availability for an email in real-time on client-side? Or check the strength of a password and display the status next to the textbox?
You can achieve the above scenarios very easy with a public method and some jQuery. I will describe the scenario when you will have to check the strength of a password:
Step1. Define a public static method that has the functionality for your action. Ex:

Step2. Decorate the public method with [WebMethod] attribute;

Step3. Add Javascript function that calls the public method from code behind. Ex:

The markup in the page will look like this:

 
Download a demo of the application:[download id=”6″ format=”1″]

Darius

Darius

Darius Dumitrescu is a creative Senior CMS Consultant with in depth .NET knowledge, focused on Web Development and Architecture Design.

Comments
  • user

    AUTHOR Kamran

    Posted on 1:13 pm February 29, 2012.
    Reply

    how about passing 2 value to code behind ?

  • user

    AUTHOR darius

    Posted on 4:17 pm March 1, 2012.
    Reply

    Hi Kamran,

    You simply pass the second parameter to the data field. Ex:

    data: “{‘password’:'” + password +”‘,’username’:”+ username+ “‘}”

    I’m not sure I have written correctly the code but I think you get the picture.

  • View Comments (0) ...
    Navigation