类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
要怎么写Web 用户控件的属性采才可以,引用控件的WEB窗体中动态控制该控件的属性。
比如:在 a.aspx 窗体中引用该Web 用户控件(PNLBox)。
则 在 a.aspx.vb文件的中怎么控制该控件(PNLBox)的属性。
比如:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
PNLBox.我定义的属性=“”
PNLBox.我定义的属性=“”
End Sub
网友回答:
1. yourusercontrol.ascx
<%@ Control Inherits="YourNS.YourCodeBehindClass" CodeBehind="yourusercontrol.ascx.cs" %>
...
2. yourusercontrol.ascx.cs
namespace YourNS
{
public class YourCodeBehindClass : UserControl
{
public string 我定义的属性
{
get {...}
set {...}
}
//...
}
}
3. yourpage.aspx
<%@ Register TagPrefix="cc" TagName="YourCodeBehindClass" src="yourusercontrol.ascx" %>
<form runat="server">
<cc:YourCodeBehindClass id="PNLBox" runat="server" />
</form>
4. yourpage.aspx.cs:
protected YourNS.YourCodeBehindClass PNLBox;
...
PNLBox.我定义的属性 = "abc";