webparts中加载updatepanel,不能实现异步更新

Lee_jsmwj 2009-02-25 04:28:58
MOSS2007的版本为SP1
参考http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3开发
已经安装ASP.NET AJAX 1.0并修改Web.config,scriptmanager使用masterpager添加和代码添加都尝试过
(参考:http://www.cnblogs.com/wangyong-wen/archive/2008/09/17/1292379.html
运行没有问题,就是没有办法异步更新,请各路大虾指点
代码如下(可执行)
using System;
using System.Collections;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using System.Runtime.InteropServices;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace UsesUpdatePanel
{
[Guid("4e393abc-cc9c-4182-8d32-a742f6ace07b")]
public class AjaxUpdatePanelPart : System.Web.UI.WebControls.WebParts.WebPart
{
private Label label;
private TextBox textBox;
private UpdatePanel up;
private Button button;
private ScriptManager _AjaxManager;

[WebPartStorage(Storage.None)]
public ScriptManager AjaxManager
{
get { return _AjaxManager; }
set { _AjaxManager = value; }
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);

_AjaxManager = ScriptManager.GetCurrent(this.Page);

if (_AjaxManager == null)
{
_AjaxManager = new ScriptManager();
_AjaxManager.EnablePartialRendering = true;

Page.ClientScript.RegisterStartupScript(typeof(AjaxUpdatePanelPart), this.ID, "_spOriginalFormAction = document.forms[0].action;", true);

if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}

this.Page.Form.Controls.AddAt(0, _AjaxManager);
}
}
}

protected override void OnLoad(EventArgs e)
{
this.EnsureUpdatePanelFixups();
base.OnLoad(e);
}

protected override void CreateChildControls()
{
base.CreateChildControls();
this.EnsureUpdatePanelFixups();
up = new UpdatePanel();
up.ID = "UpdatePanel1";
up.ChildrenAsTriggers = true;
up.RenderMode = UpdatePanelRenderMode.Inline;
up.UpdateMode = UpdatePanelUpdateMode.Always;
this.textBox = new TextBox();
this.textBox.ID = "TextBox";
up.ContentTemplateContainer.Controls.Add(this.textBox);
this.label = new Label();
this.label.Text = "Enter your name.";
up.ContentTemplateContainer.Controls.Add(this.label);
this.button = new Button();
button.CausesValidation = false;
button.ID = "Button1";
button.Text = "Say Hello";
button.Click += new EventHandler(HandleButtonClick);
up.ContentTemplateContainer.Controls.Add(this.button);
this.Controls.Add(up);
}

private void TextBoxChanged(object sender, EventArgs eventArgs)
{
this.label.Text = "Hello " + this.textBox.Text;
}

private void HandleButtonClick(object sender, EventArgs eventArgs)
{
this.label.Text = "Hello " + this.textBox.Text;
}

private void EnsureUpdatePanelFixups()
{
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
}
ScriptManager.RegisterStartupScript(this, typeof(AjaxUpdatePanelPart), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
}
}
}
...全文
96 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunyu_vip 2009-02-27
  • 打赏
  • 举报
回复
http://www.cnblogs.com/Kenr/archive/2009/02/26/1398849.html

3,242

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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