繁体   English   中英

SharePoint 2013 Web部件按钮单击事件未触发

[英]SharePoint 2013 web part button click event not firing

我正在使用Cloud 9视频作为教程来构建我的第一个Hello World Web部件。

我正在将Azure VM与SharePoint 2013,SQL Server 2012和VS Premium 2013 Update 4一起使用。

Web部件是带有按钮和标签的简单文本框。 点击事件触发一种方法,该方法将标签的文本设置为“ Hello”,再加上文本框中的文本。

    protected void btnSubmitThis_Click(object sender, EventArgs e)
    {
        lblOutput.Text = "Hello, " + txtTextBox.Text;
    }

我已经能够推送Web部件并将其插入到SharePoint 2013主页中。

点击甚至什么也没有做。 实际上,在调试中运行时,我可以看到构造函数OnInit()和Page_Load()都执行,而btnSubmitThis_Click()却没有。

Web部件确实附加了ascx.g.cs文件。

我可以看到该文件还包含以下代码,表明该事件确实正确处理了该方法:

        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    [GeneratedCodeAttribute("Microsoft.VisualStudio.SharePoint.ProjectExtensions.CodeGenerators.SharePointWebP" +
        "artCodeGenerator", "12.0.0.0")]
    private global::System.Web.UI.WebControls.Button @__BuildControlbtnSubmitThis() {
        global::System.Web.UI.WebControls.Button @__ctrl;
        @__ctrl = new global::System.Web.UI.WebControls.Button();
        this.btnSubmitThis = @__ctrl;
        @__ctrl.ApplyStyleSheetSkin(this.Page);
        @__ctrl.ID = "btnSubmitThis";
        @__ctrl.Text = "Submit";
        @__ctrl.Click -= new System.EventHandler(this.btnSubmitThis_Click);
        @__ctrl.Click += new System.EventHandler(this.btnSubmitThis_Click);
        return @__ctrl;
    }

我看不到生成的错误,单击事件根本不会调用该方法。

我在这里可能想念什么?

我已经准备好回答任何问题,因为我真的很想弄清楚这个问题,而且我已经花了几天时间独自尝试。

在此先感谢您的帮助。

根据要求添加的代码:

ascx:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HelloWorldWebPart.ascx.cs" Inherits="HelloWorld.HelloWorldWebPart.HelloWorldWebPart" %>
<p>
    Name:
    <asp:TextBox ID="txtTextBox" runat="server"></asp:TextBox>
&nbsp;<asp:Button ID="btnSubmitThis" runat="server" OnClick="btnSubmitThis_Click" Text="Submit" />
</p>
<asp:Label ID="lblOutput" runat="server"></asp:Label>

ascx.cs:

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;

namespace HelloWorld.HelloWorldWebPart
{
[ToolboxItemAttribute(false)]
public partial class HelloWorldWebPart : WebPart
{
    // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
    // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
    // for production. Because the SecurityPermission attribute bypasses the security check for callers of
    // your constructor, it's not recommended for production purposes.
    // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
    public HelloWorldWebPart()
    {
    }

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

    protected void Page_Load(object sender, EventArgs e)
    {
        int Test = 0;
    }

    protected void btnSubmitThis_Click(object sender, EventArgs e)
    {
        lblOutput.Text = "Hello, " + txtTextBox.Text;
    }
}
}

它不想用作沙盒解决方案。 尽管在场解决方案中调试起来比较困难,但它似乎更强大。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM