我用这个 html 创建了一个简单的可视化 webpart
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LinkButton.ascx.cs" Inherits="xx.xxxxDMS.WebParts.VisualWebParts.LinkButton.LinkButton" %>
<script type="text/javascript">
function OpenModalPopup(pageUrl) {
var options = { url: pageUrl, width: 900, height: 300 };
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
</script>
<asp:LinkButton ID="LnkButton" runat="server"></asp:LinkButton>
然后在后面的代码中,我添加了 3 个属性。在我使用文本链接和 url 编辑属性后,我没有看到呈现的 LinkButton。我错过了什么吗?请注意它的 SP 2013。
但我注意到控件模板文件夹中没有我的 customwebpart 的 ASCX 文件,所以我猜这在 2013 年发生了变化?
using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
namespace xx.SP.xx.WebParts.VisualWebParts.LinkButton
{
[ToolboxItemAttribute(false)]
public partial class LinkButton : WebPart
{
private string _LinkText;
private Uri _Link;
private Boolean _OpenModal;
[WebBrowsable(true), WebDisplayName("LinkText"), WebDescription("Text for the link"),
Personalizable(PersonalizationScope.Shared), Category("xx - xx"),
System.ComponentModel.DefaultValue("")]
public string LinkText
{
get { return _LinkText; }
set { _LinkText = value; }
}
[WebBrowsable(true), WebDisplayName("Link"), WebDescription("Link"),
Personalizable(PersonalizationScope.Shared), Category("xx- xx"),
System.ComponentModel.DefaultValue("")]
public Uri Link
{
get { return _Link; }
set { _Link = value; }
}
[WebBrowsable(true), WebDisplayName("OpenModal"), WebDescription("OpenModal"),
Personalizable(PersonalizationScope.Shared), Category("xx- xx"),
System.ComponentModel.DefaultValue("")]
public Boolean OpenModal
{
get { return _OpenModal; }
set { _OpenModal = value; }
}
// 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 LinkButton()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void CreateChildControls()
{
if (LnkButton != null)
{
LnkButton.Text = LinkText;
if (OpenModal)
{
LnkButton.Attributes.Add("onclick", "OpenModalPopup('" + Link.ToString() + "');");
}
else
{
LnkButton.PostBackUrl = Link.ToString();
}
}
}
}
}