2013-05-16 26 views
0

我創建了一個簡單的視覺web部件與該HTML簡單的視覺web部件時,不呈現控件

<%@ 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編輯屬性後,我沒有看到LinkBut​​ton呈現。我錯過了什麼嗎?請注意,它的SP 2013

我要去嘗試此解決方案:http://www.tfsconsulting.com.au/visual-studio-2012-sharepoint-2013-visual-web-part-project-template-is-buggy/

但我注意到,有我在控制模板文件夾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(); 
       } 
      }   
     } 
    } 
} 
+0

嘗試初始化這些值與默認開始 - 這是否工作?然後,您可以確定它的配置,或者不太有效的鏈接按鈕。 – Ian

回答

1

Sharepoint 2013 webparts的工作方式不同。 如果您將代碼從CreateChildControls移動到頁面加載,則無需使用控件模板查找控件,它將毫無問題地工作。