后台代码:
public partial class Test : System.Web.UI.Page, ICallbackEventHandler
{
public string strVal = "";
protected void Page_Load(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
string callback = cs.GetCallbackEventReference(this, "this.value", "FunTest", "this.value");
txt.Attributes.Add("onclick", callback);
}
public void RaiseCallbackEvent(string eventArgument)
{
strVal = DateTime.Now.ToString();
}
public string GetCallbackResult()
{
return strVal;
}
}
页面代码
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript">
function FunTest(resultt)
{
document.getElementById("txt").value = result ;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>