Click here to Skip to main content
15,895,799 members
Articles / Web Development / ASP.NET

Easy Way to Implement Ajax using Jquery in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.33/5 (3 votes)
28 Aug 2010CPOL3 min read 57.7K   1.1K   35  
Simple steps do an Ajax operation using Jquery and ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Jquery_Asp.Net._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Testing.... </title>

    <script src="Javascript/Ajax.js" type="text/javascript"></script>

    <script src="Javascript/ajaxupload.js" type="text/javascript"></script>

    <script src="Javascript/bsn.AutoSuggest_2.1.3.js" type="text/javascript"></script>

    <script src="Javascript/ddsmoothmenu.js" type="text/javascript"></script>

    <script src="Javascript/jquery-1.4.2.min.js" type="text/javascript"></script>

    <script src="Javascript/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script>

    <script src="Javascript/jquery.blockUI.js" type="text/javascript"></script>

    <script src="Javascript/jquery.tipsy.js" type="text/javascript"></script>

    <script src="Javascript/jquery.textarearesizer.compressed.js" type="text/javascript"></script>

    <script src="Javascript/jquery.ui.stars.js" type="text/javascript"></script>

    <script src="Javascript/jquery.validationEngine.js" type="text/javascript"></script>

    <script src="Javascript/json2.js" type="text/javascript"></script>

    <script src="Javascript/jquery_sideswap.js" type="text/javascript"></script>

    <script src="Javascript/tabletojson.js" type="text/javascript"></script>
    <style type="text/css">
    .main
    {
    	 background-color:#00FFFF;
    }
    </style>
    
    <script type="text/javascript" language="javascript">
        $(document).ready(function() {

            getUrl = function(stat) {
                var url = 'Default.aspx?ajax=1';

                if (stat)
                    url += "&status=" + stat;
                return url;

            }
            });
       function saveData(){
           $.ajax({
               type: 'POST',
               url: getUrl('test'),
               data: {
                   name: $('#frmAdd').serialize()

               },
               cache: false,
               error: function(xhr, status, errorThrown) {
                   alert(errorThrown + '\n' + status + '\n' + xhr.statusText);
               },
               success: function(html) {
                   if (html.toString().indexOf("successfully") > 0) {
                       //                    showStatus(false, html);
                       //                    clearAssessFields();
                       //                    JQDialog1.closeDialog();
                       //                    window.location.href = '../Marketing/IncentiveList.aspx';
                       alert(html);
                   }
                   else {
                       //                    showStatus(true, html);
                       alert(html);
                   }

               },
               dataType: 'html'
           });
        }
        
       
    </script>
</head>
<body>
    <form id="frmAdd" runat="server" method="post" action="Default.aspx"> 
    <div id ="main">
     <table>
     <tr>
     <td>Name
     </td><td><input type="text" id="txtName" runat="server" /> </td>
     </tr>
     <tr><td>Age</td><td><input type="text" id="txtAge" runat="server" /></td></tr>
    <tr><td></td><td><input type="button" id="btnSave" value="Save" onclick="saveData()" /></td></tr>
     </table>
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions