定义用户控件属性,用户控件值的传递
2006-08-04 20:58
330 查看
新建一个用户控件,并创建控件公共属性。WebUserControl.ascx
<%
@ Control Language="vb" AutoEventWireup="false" Codebehind="WebUse
4000
rControl.ascx.vb" Inherits="test.WebUserControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:DropDownList id="D1" runat="server">
<asp:ListItem Value="0">-请选择-</asp:ListItem>
<asp:ListItem Value="ok1">222</asp:ListItem>
<asp:ListItem Value="ok2">333</asp:ListItem>
<asp:ListItem Value="444">444</asp:ListItem>
<asp:ListItem Value="555">555</asp:ListItem>
</asp:DropDownList>
WebUserControl.ascx.vb
Public Class WebUserControlClass WebUserControl
Inherits System.Web.UI.UserControl
Private PropertyValue As String
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
End Sub
Protected WithEvents D1 As System.Web.UI.WebControls.DropDownList
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Public Property dtext()Property dtext() As String
Get
Return PropertyValue
End Get
Set(ByVal Value As String)
PropertyValue = Value
End Set
End Property
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub D1_SelectedIndexChanged()Sub D1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles D1.SelectedIndexChanged
PropertyValue = D1.SelectedItem.Value.ToString()
End Sub
End Class
在页面上引用用户控件,取得属性值并将取得的属性值显示于文本框中:uc.aspx
<%
@ Register TagPrefix="uc1" TagName="WebUserControl" Src="WebUserControl.ascx" %>
<%
@ Page Language="vb" AutoEventWireup="false" Codebehind="uc.aspx.vb" Inherits="test.uc"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>uc</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 128px" runat="server"
Text="Button"></asp:button>
<asp:TextBox id="T1" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>
<uc1:WebUserControl id="Uc1" runat="server"></uc1:WebUserControl></form>
</body>
</HTML>
uc.aspx.vb
Public Class ucClass uc
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents T1 As System.Web.UI.WebControls.TextBox
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Protected uc1 As New WebUserControl
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
T1.Text = uc1.dtext
End Sub
End Class
<%
@ Control Language="vb" AutoEventWireup="false" Codebehind="WebUse
4000
rControl.ascx.vb" Inherits="test.WebUserControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:DropDownList id="D1" runat="server">
<asp:ListItem Value="0">-请选择-</asp:ListItem>
<asp:ListItem Value="ok1">222</asp:ListItem>
<asp:ListItem Value="ok2">333</asp:ListItem>
<asp:ListItem Value="444">444</asp:ListItem>
<asp:ListItem Value="555">555</asp:ListItem>
</asp:DropDownList>
WebUserControl.ascx.vb
Public Class WebUserControlClass WebUserControl
Inherits System.Web.UI.UserControl
Private PropertyValue As String
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
End Sub
Protected WithEvents D1 As System.Web.UI.WebControls.DropDownList
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Public Property dtext()Property dtext() As String
Get
Return PropertyValue
End Get
Set(ByVal Value As String)
PropertyValue = Value
End Set
End Property
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub D1_SelectedIndexChanged()Sub D1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles D1.SelectedIndexChanged
PropertyValue = D1.SelectedItem.Value.ToString()
End Sub
End Class
在页面上引用用户控件,取得属性值并将取得的属性值显示于文本框中:uc.aspx
<%
@ Register TagPrefix="uc1" TagName="WebUserControl" Src="WebUserControl.ascx" %>
<%
@ Page Language="vb" AutoEventWireup="false" Codebehind="uc.aspx.vb" Inherits="test.uc"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>uc</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 128px" runat="server"
Text="Button"></asp:button>
<asp:TextBox id="T1" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>
<uc1:WebUserControl id="Uc1" runat="server"></uc1:WebUserControl></form>
</body>
</HTML>
uc.aspx.vb
Public Class ucClass uc
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents T1 As System.Web.UI.WebControls.TextBox
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Protected uc1 As New WebUserControl
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
T1.Text = uc1.dtext
End Sub
End Class
相关文章推荐
- 定义用户控件属性,用户控件值的传递
- 如何在用户控件中传递属性和方法(Reflection)
- asp.net定义用户控件时,属性持久化和如何动态加载的问题
- [导入]使用panelholder加载用户控件定义属性
- WPF 使用依赖属性(DependencyProperty) 定义用户控件中的Image Source属性
- 如何在用户控件中传递属性和方法(Reflection)
- 用户控件定义属性(C#:ASP.NET)
- 如何在用户控件中传递属性和方法(Reflection)(转)
- C# 定义用户控件并添加属性(制作一个限定输入的文本框)
- 如何在用户控件中传递属性和方法(Reflection)(转)
- [智能设备开发]向用户控件添加简单属性
- VS2005下自定义用户控件 如何实现属性及方法的相关智能提示
- 自定义 组合控件 与 定义属性
- 用户控件提示没有指定HtmlGenericControl的ID属性是什么错误
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)
- 使用shape来定义控件的一些显示属性
- iOS 在user defined runtime attributes(用户定义的运行时属性)改变UI