Tuesday, May 18, 2010

Simple way to user CallPage with ASP.Net

aspx Page:
---------------------------------

---------------------------------
javascript:
-----------------------
var xmlhttp
// function showHint(str) {
function showHint() {

xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert("Your browser does not support XMLHTTP!");
return;
}
var url = "http://localhost:2144/CWeb/Default3.aspx";
url = url + "&xxx=" + "1";
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
function stateChanged() {
//readyState means after the code behind is done the job
if (xmlhttp.readyState == 4) {
var Time = xmlhttp.responseText;
alert(Time);
}
}
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}




--------------------------
The Code Behind Is:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["xxx"] == "1")
{
Response.Write("One");
}
Response.Flush();
Response.End();

}

}

No comments: