doPostBack 未触发
我正在关注下一个项目: http://www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-code
ELEMENTS.XML
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="SPTest.CustomMenuItem.ButtonClicked"
RegistrationType="FileType"
RegistrationId="dtsx"
Location="EditControlBlock"
ImageUrl="/_layouts/IMAGES/DOCLINK.GIF"
Sequence="600"
Title="Execute Package"
Description="Executed Selected Package"
ControlAssembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=beb14bc625e99e7f"
ControlClass="SPTest.CustomMenuItem.CustomItemAction"
>
<UrlAction Url="javascript:__doPostBack('SPTest.CustomMenuItem.CustomItemAction', {ItemId});" />
</CustomAction>
</Elements>
PACKAGE.TEMPLATE.XML
<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="SPTest.CustomMenuItem.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=beb14bc625e99e7f"
Namespace="SPTest.CustomMenuItem" TypeName="*" Safe="True" SafeAgainstScript="False" />
</SafeControls>
</Assembly>
</Assemblies>
</Solution>
所以...在 Web.config 文件中,我们可以在 SafeControl
类中找到要执行
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SPTest.CustomMenuItem
{
public class CustomItemAction : SPLinkButton
{
protected override void OnLoad(EventArgs e)
{
this.EnsureChildControls();
base.OnLoad(e);
if (this.Page.Request["__EVENTTARGET"] == "SPTest.CustomMenuItem.ButtonClicked")
{
int itemId = Convert.ToInt32(this.Page.Request["__EVENTARGUMENT"]);
System.IO.TextWriter writer = new StreamWriter(@"C:\XXXXX\XXXXX\XXXXX\custommenuoutput.txt", true);
writer.WriteLine("Event Fired at:" + DateTime.Now.ToLongTimeString() + ": Item ID:" + itemId.ToString());
writer.Close();
}
}
}
}
的程序集如您所见,目标是执行在 Sharepoint 上分配的 SSIS 包。带有“执行包”选项的 ECB 菜单出现在所有具有 dtsx 类型的文件中。因此,当我单击此底部时,该事件不起作用...我不知道我必须做什么...任何帮助将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在 SiteAction 菜单中创建单独的操作:
ECB 菜单是使用异步请求动态填充的,因此在发布页面时,不会创建 ECB 菜单的控件,也不会触发它们的事件。虽然站点操作控件始终呈现,所以可以处理回发。
Try to create separate action in SiteAction menu:
The ECB menu is populated dynamically using async request, so on when page is posted, controls for ECB menu are not created and event for them are not fired. While Site actions controls are always rendered, so can handle postback.
重新访问您提到的页面:
http: //www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-code
他的编辑(16/02/2012) 修复了此问题(“我们还需要告诉 SharePoint 加载控件”):
然后您可以在
CustomAction
元素。这不是在他的帖子中完成的,而是在评论中提到的(我尝试了一下并且有效)。另请注意他的博客文章中的其他评论:“缺点是该控件现在将在任何地方加载,因此您必须确保除了使用 __EVENTTARGET 触发的过滤代码之外没有其他代码。”这已经在他的示例中实现了,但仍然值得注意。
Revisit the page you are mentioning:
http://www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-code
His edit (16/02/2012) fixes this issue ("We also need to tell SharePoint to load the control"):
You then can omit the attributes
ControlAssembly
andControlClass
in theCustomAction
element. This is not done in his post, but mentioned in a comment (I tried it out and it works).Please also note what other comments in his blog post say: "Drawback is that the control will load everywhere now so you have to make sure no other code, except the code you filter using the __EVENTTARGET fires." This is already implemented in his example, but still noteworty.