ClientScript.GetCallbackEventReference无刷新用法
VS2008中 运行下面代码 出错
前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="Ajax" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function CallServer(arg, context)
{
<%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context") %>;
}
function ReceiveServerData(result, context)
{
alert("ReceiveServerData"+result);
}
</script>
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1" Text="a"></asp:ListItem>
<asp:ListItem Value="2" Text="b"></asp:ListItem>
<asp:ListItem Value="3" Text="c"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Value="1" Text="a"></asp:ListItem>
<asp:ListItem Value="2" Text="b"></asp:ListItem>
<asp:ListItem Value="3" Text="c"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
后台代码
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Attributes.Add("onchange", "CallServer('FillProduct|'+this.value, 'a')");
}
#region ICallbackEventHandler 成员
public string GetCallbackResult()
{
throw new NotImplementedException();
}
public void RaiseCallbackEvent(string eventArgument)
{
throw new NotImplementedException();
}
#endregion
public string FillProduct(string categoryID)
{
return categoryID;
}
结果会提示:Microsoft JScript 运行时错误: 缺少对象
WebForm_DoCallback('__Page',arg,getResult,null,null,false)
------解决方案--------------------你把 <script type="text/javascript">
function CallServer(arg, context)
{
<%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context") %>;
}
function ReceiveServerData(result, context)
{
alert("ReceiveServerData"+result);
}
</script>
放到<head>里面去看下
------解决方案--------------------
直接JQ搞定,还用这个干什么
------解决方案--------------------