ajax无法异步刷新,各位大哥帮忙看看,弄了一下午,不知错在哪里?

wendaocy 2008-07-02 04:16:23
-------------前台------------------
<%@ 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
}
}
...全文
131 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wendaocy 2008-07-12
  • 打赏
  • 举报
回复
谢谢各位,小弟已解决。
brz97 2008-07-02
  • 打赏
  • 举报
回复
微软自带的ajax,呵呵还是算了吧,我不太愿意碰这个
还是javascript好用
yangjin123 2008-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xiaoK 的回复:]
这位老兄的代码看起来好吃力啊。实在是不好意思,眼话了。
[/Quote]

写代码 养成好习惯: 写注释
分享大哥 2008-07-02
  • 打赏
  • 举报
回复
这位老兄的代码看起来好吃力啊。实在是不好意思,眼话了。
dengchenlu 2008-07-02
  • 打赏
  • 举报
回复
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
放</System>里
wangwei155 2008-07-02
  • 打赏
  • 举报
回复
有什么错误提示?
单步调式看看执行过程

62,251

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧