doPostBack 未触发

发布于 2025-01-04 21:49:45 字数 2947 浏览 0 评论 0 原文

我正在关注下一个项目: 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 类型的文件中。因此,当我单击此底部时,该事件不起作用...我不知道我必须做什么...任何帮助将不胜感激。

I'm following the next project: 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>

So... In Web.config file we can find our assembly in SafeControl

CLASS TO EXECUTE

   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();
                }
            }
        }
    } 

As you can see, the objective is to execute a SSIS package that is allocate on Sharepoint. A ECB menu with Execute Package option appeared in all files that have dtsx type. Therefore when I clicked in this bottom, the event doesn't work... I don't know what I have to do... Any helped will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2025-01-11 21:49:45

尝试在 SiteAction 菜单中创建单独的操作:


Sequence="1000" Title="自定义操作调度程序"
ControlAssembly =“SPTest.CustomMenuItem,版本= 1.0.0.0,
文化=中立,PublicKeyToken=beb14bc625e99e7f”
ControlClass="SPTest.CustomMenuItem.CustomItemAction">

ECB 菜单是使用异步请求动态填充的,因此在发布页面时,不会创建 ECB 菜单的控件,也不会触发它们的事件。虽然站点操作控件始终呈现,所以可以处理回发。

Try to create separate action in SiteAction menu:

<CustomAction Id="SPTest.CustomMenuItem.CustomActionsDispatcher"
GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000" Title="Custom Actions Dispatcher"
ControlAssembly="SPTest.CustomMenuItem, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=beb14bc625e99e7f"
ControlClass="SPTest.CustomMenuItem.CustomItemAction">
</CustomAction>

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.

故事还在继续 2025-01-11 21:49:45

重新访问您提到的页面:

http: //www.thorntontechnical.com/tech/sharepoint/sharepoint-2010-context-menu-item-with-custom-code

他的编辑(16/02/2012) 修复了此问题(“我们还需要告诉 SharePoint 加载控件”):

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control ControlAssembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken={PublicKeyToken}"
ControlClass="SPTest.CustomMenuItem.CustomItemAction" Sequence="50" Id="AdditionalPageHead"/>
<CustomAction ...

然后您可以在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"):

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control ControlAssembly="SPTest.CustomMenuItem, Version=1.0.0.0, Culture=neutral, PublicKeyToken={PublicKeyToken}"
ControlClass="SPTest.CustomMenuItem.CustomItemAction" Sequence="50" Id="AdditionalPageHead"/>
<CustomAction ...

You then can omit the attributes ControlAssembly and ControlClass in the CustomAction 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文