Click here to Skip to main content
15,886,873 members
Articles / Web Development / ASP.NET
Tip/Trick

Debugging jQuery in ASP.NET

Rate me:
Please Sign up or sign in to vote.
1.80/5 (4 votes)
28 Apr 2013CPOL 32.8K   4   8
When an ASP.NET developer using jquery or javascript (clientside programming) in his code, so always a question arise, how I debug this code.

Introduction

When an ASP.NET developer uses jQuery or JavaScript (clientside programming) in his code, the question always arises of how to debug this code. We can debug in code behind with breakpoints. But what for clientside scripting. Some people say use "alert()", but I don't think this is a sufficient way to do it.

So the good news is that we have "debugger". Use debugger before your code, where you want to start debugging.

Using the code

XML
<html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title></title>

        <script src="Scripts/jquery-1.7.1.min.js"></script>

        <script>

            $(document).ready(function () {


                $(':radio').click(function () {

                    debugger;

    //Get the value of Radio button

                    var _GetVal = $(this).attr('value');

                });

             });


        </script>


    </head>

    <body>

        <form id="form1" runat="server">

        <div>

            First

            <input type="radio" name="rd1" value="10" />

            <input type="radio" name="rd1" value="11" />

            Second

            <input type="radio" name="rd1" value="12" />

            <input type="radio" name="rd1" value="13" />

        </div>

        </form>

    </body>

    </html>

This is a simple ASP.NET in page code. When the user clicks a radio button, debugging will automatically start, due to the debugger command. In the above program, when the user clicks on the radio button we stored its value in the _Getval variable.

C#
$(document).ready(function () {


                $(':radio').click(function () {

                    debugger;

    //Get the value of Radio button

                    var _GetVal = $(this).attr('value');

                });

             });

When you click in any radio button , automatically your debugging will start.

So with the use of the debugger you can start your debugging in ASP.NET.

And please remember, when you finish debugging or publish your page, please remove debugger from your code.
If you have any query, Please send your valuable Comments. Happy Programming.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
QuestionThanks for telling this Pin
surbhi Arora6-Feb-14 23:54
surbhi Arora6-Feb-14 23:54 
AnswerRe: Thanks for telling this Pin
Mishra Sourabh9-Feb-14 1:46
Mishra Sourabh9-Feb-14 1:46 
QuestionThanks for telling us about this. Pin
surbhi Arora6-Feb-14 23:53
surbhi Arora6-Feb-14 23:53 
GeneralMy vote of 1 Pin
ednrg29-Apr-13 3:34
ednrg29-Apr-13 3:34 
Those days are over. Use FireBug or Developers Tools.
GeneralMy vote of 1 Pin
Ravi Gadag28-Apr-13 23:48
Ravi Gadag28-Apr-13 23:48 
GeneralRe: My vote of 1 Pin
Ashraf Sabry29-Apr-13 9:27
Ashraf Sabry29-Apr-13 9:27 
GeneralRe: My vote of 1 Pin
Ravi Gadag29-Apr-13 17:44
Ravi Gadag29-Apr-13 17:44 
GeneralMy vote of 1 Pin
User 786675228-Apr-13 9:48
User 786675228-Apr-13 9:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.