我正在尝试将 XsltListViewWebPart 控件动态添加到共享点应用程序。当我在 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>
引发ajax调用的Javascript函数
function test()
{
var ajaxMgr = $find("<%= RadAjaxManager.GetCurrent(this).ClientID %>");
if (ajaxMgr)
{
ajaxMgr.ajaxRequest("Name1;Value1");
}
}
提前致谢 :-)