62,254
社区成员
发帖
与我相关
我的任务
分享

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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></title>
<script type="text/javascript">
function bindFun()
{
document.getElementById("button1").onclick = addATextInput;
document.getElementById("button2").onclick = getValueFromServer;
}
function addATextInput()
{
var text = document.createElement("input");
text.setAttribute("type", "text");
text.setAttribute("value", "凤姐");
text.setAttribute("id", "text1");
document.body.appendChild(text);
}
function getValueFromServer()
{
if (document.getElementById("text1") == null)
alert('先按button1创建一个text');
else
document.getElementById("text1").value = _Default.abc('祝你').value;
}
</script>
</head>
<body onload="bindFun()">
<form id="form1" runat="server">
<div>
<input id="button1" type="button" value="Button1" />
<input id="button2" type="button" value="Button2" />
</div>
</form>
</body>
</html>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(_Default));
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public string abc(string para)
{
return para + "新年快乐!";
}
}<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
<httpHandlers>