简体   繁体   English

无法将控件添加到用户控件

[英]can't add control to usercontrol

This works: 这有效:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Comments.ascx.cs" Inherits="Controls_Comments" %>

Add comment

But this: 但是这个:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Comments.ascx.cs" Inherits="Controls_Comments" %>

Add comment
<asp:Button runat="server" ID="lol" />

Throws this error I've never seen before: 引发这个我从未见过的错误:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.UI.Control.ApplyStyleSheetSkin(System.Web.UI.Page)' has some invalid arguments

Source Error:


Line 190:            #line hidden
Line 191:            this.lol = @__ctrl;
Line 192:            @__ctrl.ApplyStyleSheetSkin(this.Page);
Line 193:            
Line 194:            #line 5 "C:\inetpub\wwwroot\ScirraNew\Controls\Comments.ascx"

Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\scirranew\3a1c901c\f2f0205e\App_Web_comments.ascx.cc671b29.aem6dvrt.0.cs    Line: 192 

Any help appreciated, I can't see much on google about it :( I have added it to web.config this way: 任何帮助表示赞赏,我在Google上看不到太多了:(我已通过以下方式将其添加到web.config中:

<add tagPrefix="Scirra" src="~/Controls/Comments.ascx" tagName="Comments"/>

Page code behind: 页面代码后面:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_Comments : System.Web.UI.UserControl
{
    /// <summary>
    /// Anchor (GUID/UniqueIdentifier) for the comments
    /// </summary> 
    public System.Guid Anchor { get; set; }

    /// <summary>
    /// Comment page to load
    /// </summary>
    public int Page { get; set; }

    public int TotalComments { get; set; }
    public int TotalPage { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

If I understand correctly, your declaring a public property named Page, which is an integer: 如果我理解正确,则您声明一个名为Page的公共属性,它是一个整数:

public int Page { get; set; }

And then your using this property to apply the stylesheet skin: 然后,您使用此属性来应用样式表外观:

@__ctrl.ApplyStyleSheetSkin(this.Page);

Try renaming your property to something else (PageCount, NumberOfItemsOnPage, PageID, etc.). 尝试将您的属性重命名为其他名称(PageCount,NumberOfItemsOnPage,PageID等)。 Or assign the correct type to this property: 或为此属性分配正确的类型:

public System.Web.UI.Page Page { get; set; }

Also had this strange issue and it had me pulling my hair out. 也有这个奇怪的问题,它让我拔头发。 Then I hit me.... 然后我打我...

1.) I had started a new VS 2010 C# Web project 1.)我已经开始了一个新的VS 2010 C#Web项目

2.) I deleted a bunch of the auto-generated project files (including Site.Master) 2.)我删除了一堆自动生成的项目文件(包括Site.Master)

3.) I started building up my basic code framework 3.)我开始建立我的基本代码框架

4.) I created a new Site.Master file 4.)我创建了一个新的Site.Master文件

5.) When I added the first server control (Label) to the Site.Master I started getting the error 5.)当我将第一个服务器控件(Label)添加到Site.Master时,我开始收到错误消息

6.) Then it hit me, maybe something was stuck in temp files, designer files, or cache where it was still trying compile (call it a) ghost (for a lack of a better term) of the original Site.Master file that did not have the new Label control added. 6.)然后它击中了我,也许有些东西卡在了临时文件,设计器文件或高速缓存中,但仍在尝试编译(称其为)幽灵(缺少更好的术语)原始的Site.Master文件,没有添加新的Label控件。

I renamed my new Site.Master file to SiteMaster.Master and the site operated correctly again. 我将新的Site.Master文件重命名为SiteMaster.Master,站点再次正常运行。 (Obviously I had to update all my child pages to use the new correct master page). (显然,我必须更新所有子页面才能使用新的正确母版页)。

Not sure where the original Site.Master ghost file was hiding. 不知道原始Site.Master幻影文件在哪里隐藏。 Even tried killing all the Temporary ASP.NET Files from C:\\, Rebuilding Project, Clean Project, restarting VS, restarting PC, etc. Super weird. 甚至尝试过从C:\\杀死所有的临时ASP.NET文件,重建项目,清理项目,重新启动VS,重新启动PC等。超级奇怪。

But just thought I'd share this stupid mistake that ran me in circles for 20 minutes before I figured it out! 但是我以为我会分享这个愚蠢的错误,在我弄清楚这个错误之前,我在圈子里跑了20分钟!

Best! 最好!

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

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