2011-12-12 46 views
0

我试图在asp.net中扩展中继器控制。例如,我想添加按钮,将控件中的颜色从黑色变为红色(这只是一个示例)。通过添加按钮来扩展中继器

我创建网站的用户控制和改变继承自

public partial class MyRepeater : System.Web.UI.UserControl 

到:

public partial class MyRepeater : Repeater 

ASCX:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyRepeater.ascx.cs" Inherits="System.Web.UI.WebControls.Repeater" %> 

然后在ASCX我想添加的按钮,但有编译时出错:

ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). 

我怎样才能easilly扩展中继器的一个按钮(我需要扩大原因在实际的例子中,这个按钮将做别的事情,所以其他解决方案,chage颜色不会帮助我)。

感谢任何提示

回答

0

编辑:看准错误是不是我首先想到......

要更改用户控件的服务器控件扩展因此

extends the correct base class (e.g. Page or UserControl <---- Note by extending Repeater you now no longer extend UserControl) 

什么你需要做的是创建一个ServerControl(在没有ascx.cs位的情况下自己创建一个类,你应该没问题,你需要开始专注于服务器控件的开发,特别是DataBoundControl,也可以阅读Render方法等等。我建议st只是一个很好的一般阅读在MSDN的服务器控制创作

+0

仍然同样的错误 – gruber

+0

改变,以反映错误@gruber,并添加了你需要看看_可能会敲你一个快速的服务器控制扩展中继器,但我认为通过阅读MSDN中的文章你会获得更多收益 –