Click here to Skip to main content
15,886,513 members
Articles / Web Development / HTML

AJAX Enabled Layered Web Application

Rate me:
Please Sign up or sign in to vote.
1.81/5 (6 votes)
23 Apr 20075 min read 55.3K   308   37  
Building AJAX Enabled Layered Web Applications with Microsoft ASP.NET 2.0
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Accounts._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 id="Head1" runat="server">
	<title>Accounts</title>
	<script type='text/javascript' language="javascript">
	    function fnBindGrid()
	    {
	        PostXmlHttp('AjaxAccess.asmx/WsBindGrid', 'CBBindGrid', 'SQL=SELECT * FROM ACCOUNTTYPES');
	        
	    }
	    function CBBindGrid()
	    {
	        //State Description 
		    //0 The request is not initialized 
		    //1 The request has been set up 
		    //2 The request has been sent 
		    //3 The request is in process 
		    //4 The request is complete 
		    try
		    {
			    if (xmlHttp.readyState==4)
			    { 
				    document.all.item("HiddenDiv").style.display = "none";
				    ParseXml(xmlHttp.responseText);
                    if(returnParseXml != null)
				    {
                        var myData = [,];
                        myData = eval(returnParseXml.childNodes[0].nodeValue);
                        var htmlTable; 

	                    if(myData.length > 0)
	                    {
	                        var rows = myData.length;
	                        var columns = myData[0].length;
	                        //loop through the rows
	                        htmlTable = '<TABLE>';
	                        for( i = 0 ; i < rows ; i++)
	                        {
	                            htmlTable += '<TR>';
	                            //loop through the columns
	                            for( j = 0 ; j < columns ; j++ )
	                            {
	                                htmlTable += '<TD>';
	                                    htmlTable += myData[i][j];
	                                htmlTable += '</TD>';
	                                //alert(myData[i][j]);
	                                
	                            }	
	                            htmlTable += '</TR>';	
	                                                     
	                        }
	                        htmlTable += '</TABLE>';
	                        CustTable.innerHTML = htmlTable;
	                        
                        }
                    				        
                    }
				    else
				        alert('Failed: Return XML not found');
				        
			    }
			    
		    }
		    catch(e)
		    {
			    alert(e.Message);
			    
		    }
	    }
	    
        function fnSaveAccountType()
        {
		   PostXmlHttp('AjaxAccess.asmx/WsSaveAccountType', 'CBSaveAccountType', 'AccountType='+Trim(document.all.item("txtAccountType").value));
		   
        }

	    function CBSaveAccountType()
	    {
		    //State Description 
		    //0 The request is not initialized 
		    //1 The request has been set up 
		    //2 The request has been sent 
		    //3 The request is in process 
		    //4 The request is complete 
		    try
		    {
			    if (xmlHttp.readyState==4)
			    { 
				    document.all.item("HiddenDiv").style.display = "none";
				    ParseXml(xmlHttp.responseText);
                    if(returnParseXml != null)
				    {
				        if(Trim(returnParseXml.childNodes[0].nodeValue) == 'Success')
				        {
				            alert('Saved Successfully');
				            fnBindGrid();
				        }
				        else
				            alert(returnParseXml.childNodes[0].nodeValue);

                    }
				    else
				        alert('Failed: Return XML not found');
				        
			    }
			    
		    }
		    catch(e)
		    {
			    alert(e.Message);
			    
		    }
	    }	    
	</script>    
</head>
<body>
    <form id="form1" runat="server">
    <div>
	    <div id='CustTable'></div>
        <asp:GridView ID="gvAccountTypes" runat="server"></asp:GridView>
        <input id="txtAccountType" type="text" />
        &nbsp;
        <input id="Button1" type="button" value="Save" onclick="fnSaveAccountType()" />&nbsp;
    </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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


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

Comments and Discussions