我正在使用Cloud 9视频作为教程构建我的第一个Hello World Web部件。
我正在使用带有SharePoint 2013,SQL Server 2012和VS Premium 2013 Update 4的Azure VM。
Web部件是一个带有按钮和标签的简单文本框。 click事件触发一个方法,该方法将标签文本设置为“Hello”,+文本框中的文本。
protected void btnSubmitThis_Click(object sender, EventArgs e)
{
lblOutput.Text = "Hello, " + txtTextBox.Text;
}
我已经能够推送我的Web部件并将其插入到我的SharePoint 2013主页中。
点击甚至什么都不做。实际上,当在debug中运行时,我可以看到构造函数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>
<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;
}
}
}
答案 0 :(得分:0)
它不想作为沙盒解决方案工作。尽管在服务器场解决方案中调试更难,但它似乎更强大。