Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • preventDefault() function in JQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 37
    Comment on it

    In MVC projects or in any .NET projects when we use the controls which are not of pure HTML type the page rendering or postback gets occurred.

     

     

    So for this we need to make sure that you use the function that will not get your control and data lost when the JQuery function is invoked.

     

     

    So for doing it we have two ways first we can use preventDefault() function or at last we can return false before the function ends.

     

     

    First way

     

      $(".lnkEdit").live("click", function (e) {
                var id = $(this).attr('id');
                 url = '@Url.Content("~/Home/_Edit")/' + id;
                $("#dialog-edit").dialog('open');
                $.get(url,function (result) {
                    alert(result);
                     $("#dialog-edit").html(result);
                });
    
    
                $(".ui-dialog-title").html("Update User");
                $("#dialog-edit").dialog('open');
                return false;
            });
    

     

     

    Second Way

      $(".lnkEdit").live("click", function (e) {
                var id = $(this).attr('id');
                 url = '@Url.Content("~/Home/_Edit")/' + id;
                $("#dialog-edit").dialog('open');
                $.get(url,function (result) {
                    alert(result);
                     $("#dialog-edit").html(result);
                });
    
                $(".ui-dialog-title").html("Update User");
                $("#dialog-edit").dialog('open');
                e.preventDefault();
            });
    
    

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: