使用回调功能
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="postback.aspx.cs" Inherits="WebApplication6.postback" %>
<!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>Callpck page</title>
<script type="text/javascript">
function GetNumber() {
UseCallback();
}
function GetRandomNumber(TextBox1, context) {
document.forms[0].Textbox1.value = TextBox1;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btn1" onclick="GetNumber()" value="得到随机数" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</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;
namespace WebApplication6
{
public partial class postback : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
private string _callbackResult = null;
protected void Page_Load(object sender, EventArgs e)
{
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "GetRandomNumber", "context");
string cbScript = "function useCallback(arg,context)" + "{" + cbReference + ";" + "}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cbScript, true);
}
public void RaiseCallbackEvent(string eventArg)
{
Random rnd = new Random();
_callbackResult = rnd.Next().ToString();
}
public string GetCallbackResult()
{
return _callbackResult;
}
}
}
调试的时候一直出现UseCallback未定义。我也是才看这块东西的,有点不明白... --------------------编程问答-------------------- 你的JS里面没有UseCallback这个方法
应该重新定义
funtcion UseCallback()--------------------编程问答-------------------- 问题不是像你说的那样 --------------------编程问答-------------------- 你在后台function useCallback(
{
//执行操作
}
是小写的,然而你在调用的时候用的UseCallback,能找得到么?和没有定义有什么区别 --------------------编程问答-------------------- 谢了 一点小问题 现在解决了
补充:.NET技术 , ASP.NET