Sample example:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_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>Ajax Page</title>
<style type="text/css" media="screen">
body{
font-family: Verdana;
font-size: 11px;
}
#content{
background-color: #CCCCCC;
}
#button{
font-family: Verdana;
font-size: 10px;
}
</style>
<script type ="text/_javascript" language="_javascript">
var xml;
function GetData()
{
xml=getXMLHTTPRequest();
if(xml!=null)
{
xml.onfiltered= ProcessResponse;
xml.open("GET", "NewAjax.aspx", true);
xml.send(null);
}
return false;
}
function getXMLHTTPRequest()
{
var xRequest=null;
if (window.XMLHttpRequest) {
xRequest=new XMLHttpRequest();
}else if (typeof ActiveXObject != "undefined"){
xRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
return xRequest;
}
function ProcessResponse()
{
if(xml.readyState == 4)
{
if(xml.status == 200)
{
var retval=xml.responseText;
if (document.getElementById("lblAjaxData")!=null)
document.getElementById("lblAjaxData").inn_erhtml=retval;
}
else
{
alert("Error retrieving data!" );
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
<asp:Label ID="lblAjaxData" runat="server"></asp:Label>
</div>
<br />
<div id="button">
<asp:Button ID="btnGetData" runat="server" Text="Get Ajax Data Now!!!" />
</div>
</form>
</body>
</html>
Here the core of the program is the _javascript method which creates the HttpRequest for the page which is to send output. Here you can create any output either from a database or any processing. This output is handled by the ProcessResponse method.
NEWAJAX.aspx
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("Current Time : " & DateTime.Now)
Response.End()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ajax Output</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Hope this example gives you a heads on to your Ajax Program
No comments:
Post a Comment