ajax无法异步刷新,各位大哥帮忙看看,弄了一下午,不知错在哪里?
-------------前台------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="menu_update.aspx.cs" Inherits="Dzw.admin_menu_update" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link href="../App_Themes/css/admin_jndex.css" rel="stylesheet" type="text/css" />
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<script type="text/javascript">
function CallServer()
{
var str1 = document.all.firstbox.value;
var str2 = document.all.sencondbox.value;
UpdatePanel1.innerHTML ="<img id='img1' src='../images/loading_small.gif' />...";
arg = str1+'|'+str2;
// alert(arg);
<%=ClientScript.GetCallbackEventReference(this,"arg","ReceiveServerData","UpdatePanel1")%>;
}
function ReceiveServerData(result,UpdatePanel1)
{
UpdatePanel1.innerHTML = result;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="3" cellspacing="1" border="0" width="100%" align=center>
<tr><td colspan=2 height=25 class="td_title_m">
菜单修改</td></tr>
<tr><td height=23 colspan=2>
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
</asp:UpdatePanel>
</td></tr>
<tr>
<td height=23 style="width: 10%">
一级菜单:<b></b></td>
<td width="50%" class="forumRow">
<asp:TextBox ID="firstbox" CssClass="input" runat="server" Width="213px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 10%; height: 24px;">
二级菜单:<b></b>
</td>
<td width="60%" class="forumRow" style="height: 24px">
<asp:TextBox ID="sencondbox" CssClass="input" runat="server" Width="214px"></asp:TextBox>
</td>
</tr>
<tr><td height=23 colspan=2>
<Button type="button" ID="Button1" onMousemove="this.className='button_on'" onMouseout="this.className='button'" TabIndex="8" onclick="CallServer()" > 修 改</button>
<Button type="button" ID="Button2" onMousemove="this.className='button_on'" onMouseout="this.className='button'" onclick="javascript:window.location.href='Admin_Menu.aspx';" TabIndex="8" >取 消</button></td></tr>
</table>
</div>
<br/>
</form>
</body>
</html>
------后台--------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.Common;
using System.Data.OleDb;
using System.Drawing;
namespace Dzw
{
public partial class admin_menu_update : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
private PageBase DzwBase = new PageBase();
public string theID;
public string pid;
private DataTable tb = new DataTable();
public string strSql;
string result;
protected void Page_Load(object sender, EventArgs e)
{
theID = Request.QueryString["id"];//一级目录id
pid = Request.QueryString["pid"];//二级目录id
if (pid.Length == 0)
strSql = "SELECT a.Menu_Id as id,a.Menu_Name AS 一级栏目, b.Menu_Name AS 二级栏目 FROM Dz_Menu AS a LEFT OUTER JOIN Dz_Menu AS b ON a.Menu_Id = b.Parent_Id WHERE (a.Parent_Id IS NULL) and a.Menu_id=" + theID;
else
strSql = "SELECT a.Menu_Id as id,a.Menu_Name AS 一级栏目, b.Menu_Name AS 二级栏目 FROM Dz_Menu AS a LEFT OUTER JOIN Dz_Menu AS b ON a.Menu_Id = b.Parent_Id WHERE (a.Parent_Id IS NULL) and b.Menu_id="+pid+" and b.parent_id ="+theID+"";
DzwBase.DBOpen();
tb = DzwBase.ExecuteSql4Ds(strSql).Tables[0];
GetData();
DzwBase.DBClose();
}
protected void GetData()
{
firstbox.Text = tb.Rows[0][1].ToString().Trim();
sencondbox.Text = tb.Rows[0][2].ToString().Trim();
if ((bool)(sencondbox.Text.ToString().Trim().Length == 0))
{ sencondbox.Enabled = false; }
}
//*---此函数实现ajax异步操作,并返回一个字符串给GetCallbackResult函数---*//
public void RaiseCallbackEvent(string eventArgument)
{
DzwBase.DBOpen();
String[] param = eventArgument.Split('|');
DzwBase.Execute("update Dz_Menu set Menu_Name ='" + param[0] + "' where Menu_Id =" + theID + "");
if(pid.Length !=0)
{
DzwBase.Execute("update Dz_Menu set Menu_Name ='" + param[1] + "' where Menu_Id =" + pid + "");
}
//Response.Write(param[0]);
result = "";
DzwBase.DBClose();
}
//*---此函数实现返回值的回调,回调值可对服务器端控件值进行修改---*//
public string GetCallbackResult()
{
return result;
}
#region ICallbackEventHandler 成员
string ICallbackEventHandler.GetCallbackResult()
{
throw new Exception("The method or operation is not implemented.");
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}