谢谢楼上的,已经做到这一步了,但是用户控件的Label不会变化 代码如下: 用户控件后台代码: Private _Color As System.Drawing.Color Private _Txt As String ''' <summary> ''' 设置显示信息是否为错误信息 ''' </summary> ''' <value></value> ''' <res></res> Public WriteOnly Property MStype() As Boolean Set(value As Boolean) If value = True Then _Color = Drawing.Color.Black Else _Color = Drawing.Color.Red End If End Set End Property ''' <summary> ''' 定义显示提示的文本内容 ''' </summary> ''' <value></value> ''' <res></res> Public WriteOnly Property MSText() As String Set(value As String) _Txt = value End Set End Property Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load ShowText() End Sub Private Sub ShowText() Label1.ForeColor = _Color Label1.Text = _Txt End Sub调用的方法: Private Sub ShowMsg(C As manage_Controls_message, T As String, B As Boolean) C.Page.LoadControl("Controls/message.ascx") C.Visible = True C.MSText = T C.MStype = B End Sub在单击按钮事件时执行下面的代码: ShowMsg(message1, "靠!", False)
代码如下:
用户控件后台代码:
Private _Color As System.Drawing.Color
Private _Txt As String ''' <summary>
''' 设置显示信息是否为错误信息
''' </summary>
''' <value></value>
''' <res></res>
Public WriteOnly Property MStype() As Boolean
Set(value As Boolean)
If value = True Then
_Color = Drawing.Color.Black
Else
_Color = Drawing.Color.Red
End If
End Set
End Property ''' <summary>
''' 定义显示提示的文本内容
''' </summary>
''' <value></value>
''' <res></res>
Public WriteOnly Property MSText() As String
Set(value As String)
_Txt = value
End Set
End Property Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
ShowText()
End Sub Private Sub ShowText()
Label1.ForeColor = _Color
Label1.Text = _Txt
End Sub调用的方法:
Private Sub ShowMsg(C As manage_Controls_message, T As String, B As Boolean)
C.Page.LoadControl("Controls/message.ascx")
C.Visible = True
C.MSText = T
C.MStype = B
End Sub在单击按钮事件时执行下面的代码:
ShowMsg(message1, "靠!", False)
TestWebUserControl1.SetNewValue();
这样貌似是不能调用SetNewValue()方法的
Label1.ForeColor = _Color
Label1.Text = _Txt
End Sub这个方法最开始是public的,但是无法调用
x.MSText = T
x.MStype = B
Page.Form.Controls.Add(x)
<uc1:TestWebUserControl ID="TestWebUserControl1" runat="server" Text="A" Color="green" />
放入页面是可以调用方法的
<uc2:message ID="message1" runat="server" Visible="False" />‘在后台代码中,调用ShowText无法找到该方法,LoadControl加不加没什么意义,这个只是动态加载,但是我的用户控件已经拖入页面,只是希望在事件中更改其属性
message1.ShowText()
message1.ShowText()
可以调用了,尴尬啊,为啥原来的页面不行呢