簡體   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