求助,用户控件属性继承问题
创建了一个用户控件wucTextBox,其中有一个TextBox控件,
引用后,wucTextBox 不能引用TextBox控件的属性和事件,
请问如何解决,最好能给予代码,谢谢!
[解决办法]
能写的具体些嘛
[解决办法]
简单点说就是
在用户控件wcuTextBox中有一个TextBox控件TextBox1
我希望能在wcuTextBox控件的属性中能够直接包含TextBox1控件的所有属性
[解决办法]
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="wucTextBox.ascx.vb" Inherits="IMIS.wucTextBox" %>
<link href="../Skin/Default.css" rel="stylesheet" type="text/css" />
<asp:TextBox ID="TextBox1" runat="server" CssClass="textbox_Hx" Width="60px"></asp:TextBox>
Public Class wucTextBox
Inherits TextBox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.BackColor = Drawing.Color.Transparent
TextBox1.Width = Width
End Sub
Private tmpWidth As Integer = 100
Public Property Width As Integer
Get
Width = tmpWidth
End Get
Set(value As Integer)
tmpWidth = value
End Set
End Property
Private tmpHeight As Integer = 20
Public Property Height As Integer
Get
Height = tmpHeight
End Get
Set(value As Integer)
tmpHeight = value
End Set
End Property
End Class
'------------------------------------------
' <自动生成>
' 此代码由工具生成。
'
' 对此文件的更改可能会导致不正确的行为,并且如果
' 重新生成代码,这些更改将会丢失。
' </自动生成>
'------------------------------------------
Option Strict On
Option Explicit On
Partial Public Class wucTextBox
'''<summary>
'''TextBox1 控件。
'''</summary>
'''<remarks>
'''自动生成的字段。
'''若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
'''</remarks>
Protected WithEvents TextBox1 As Global.System.Web.UI.WebControls.TextBox
End Class
[解决办法]
Public Class wucTextBox
Inherits TextBox '这里更改过,原先是Inherits System.Web.UI.UserControl,不报错,但不能显示TextBox1的属性,变了之后报错:分析器错误消息: “IMIS.wucTextBox”不扩展类“System.Web.UI.UserControl”,因此此处不允许。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.BackColor = Drawing.Color.Transparent
TextBox1.Width = Width
End Sub
Private tmpWidth As Integer = 100
Public Property Width As Integer
Get
Width = tmpWidth
End Get
Set(value As Integer)
tmpWidth = value
End Set
End Property
Private tmpHeight As Integer = 20
Public Property Height As Integer
Get
Height = tmpHeight
End Get
Set(value As Integer)
tmpHeight = value
End Set
End Property
End Class