技术开发 频道

Ajax调用后类方法时报”对象未定义“错误解决方法


【IT168技术文档】

  bug现象:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Ajax.Utility.RegisterTypeForAjax(typeof(Test_myDesktop)); } }
桌面设置的保存、修改和删除方法#region 桌面设置的保存、修改和删除方法
/**//// <summary> /// 异步方法 用来得到每个用户的桌面设置  /// </summary> /// <returns></returns> [AjaxMethod(HttpSessionStateRequirement.Read)] public string GetSetting() { string setting = string.Empty; try { SMUser currentUser = HttpContext.Current.Session["User"] as SMUser; if (null != currentUser) { string selectString = string.Format("select desktopsettings from sm_user where user_sysId='{0}'", currentUser.USER_SYSID); setting = SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, selectString). ToString(); } } catch (Exception ex) { setting = ""; } return setting; } #endregion
  利用Ajax.dll来完成异步保存用户设置时,出现"对象未定义”的错误。
  尝试解决方法: 首选确认bin文件夹下ajax.dll的引用;并且在web.config中添加了
<httpHandlers> <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/> </httpHandlers>
  (没错。这些我都做),然后检查代码以及类型注册。这部分也没有错。(我的部分代码如下:)
  后台代码:
using Ajax; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Ajax.Utility.RegisterTypeForAjax(typeof(Test_myDesktop)); } } 桌面设置的保存、修改和删除方法#region 桌面设置的保存、修改和删除方法 /**//// <summary> /// 异步方法 用来得到每个用户的桌面设置  /// </summary> /// <returns></returns> [AjaxMethod(HttpSessionStateRequirement.Read)] public string GetSetting() { string setting = string.Empty; try { SMUser currentUser = HttpContext.Current.Session["User"] as SMUser; if (null != currentUser) { string selectString = string.Format("select desktopsettings from sm_user where user_sysId='{0}'", currentUser.USER_SYSID); setting = SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, selectString). ToString(); } } catch (Exception ex) { setting = ""; } return setting; } #endregion
0
相关文章