我正在尝试动态地将XsltListViewWebPart控件添加到sharepoint应用程序。 当我在Page_Load上运行ShowDocumentList(pnlAdminCurrentDocuments)时,一切正常。
但是,如果我在ajax请求上调用相同的函数,控件会加载,但没有任何事件被触发(即排序,扩展树视图等)
XsltListViewWebPart wp;
private void ShowDocumentList(Panel panel)
{
try
{
ShowMessage("<p>No documents to show</p>");
string meetingURL = "http://rl01/sites/nmc/FullMonty";
string meetingId = "6d39de81-a7f7-4cff-9c94-5d2893526dc5";
if (!string.IsNullOrEmpty(meetingURL) && !string.IsNullOrEmpty(meetingId))
{
using (SPSite site = new SPSite(meetingURL))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList("Meeting Documents");
if (list == null)
return;
SPView view = null;
try
{
view = list.Views["Submitted"];
//view = list.Views[0];
}
catch { }
if (view == null)
{
//todo - replace with toolbx message
ShowMessage("Cannot view documents");
}
else
{
wp = new XsltListViewWebPart();
wp.ChromeType = PartChromeType.None;
wp.ListId = list.ID;
wp.ViewGuid = view.ID.ToString();
wp.WebId = web.ID;
wp.XmlDefinition = view.GetViewXml();
wp.XmlDefinition = wp.XmlDefinition.Replace("MEETING_ID", meetingId);
//SetToolbarContext(web);
panel.Controls.Clear();
panel.Controls.Add(wp);
}
}
}
}
}
catch (Exception ex)
{
ShowMessage("");
}
}
该函数实际获取数据并完成所有操作,但列表视图中的任何客户端功能都不起作用。即使我将鼠标悬停在列名称上也会引发javascript错误。如果我使用完整的回发添加控件而不使用ajax,一切都按预期工作。
protected void radAjaxMgr_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
ShowDocumentList(pnlAdminCurrentDocuments);
}
HTML标记如下
<telerik:RadAjaxManager ID="radAjaxMgr" runat="server" OnAjaxRequest="radAjaxMgr_AjaxRequest">
</telerik:RadAjaxManager>
<asp:UpdatePanel runat="server" ID="pnl1">
<ContentTemplate>
<asp:Panel ID="pnlAdminCurrentDocuments" runat="server" CssClass="i3q_DocumentListHldr submittedDocsPanel">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Javascript函数提升ajax调用
function test()
{
var ajaxMgr = $find("<%= RadAjaxManager.GetCurrent(this).ClientID %>");
if (ajaxMgr)
{
ajaxMgr.ajaxRequest("Name1;Value1");
}
}
提前致谢: - )