-
How to expose server control properties from a Web User Control?
I have a dilemma. I created an ASP.Net Web User Control with an asp:label
on it. Then I dragged that control onto an .aspx web form. What I need
to do is to write code in my ASPX code behind that allows me to SET the label's
text property at runtime. In all the examples I am finding, it appears that
the server control's within a User Control can only be set from code WITHIN
the user control itself.
Does anyone know how to expose the text property of the label in the User
Control in such a way that the ASPX page it resides on can set the text property?
A simple example would be that when the client types in a value in a textbox
on the web page and then clicks a button, the Label on the User Control has
its text property set to the text in the text box.
Thanks in advance,
Todd
-
Re: How to expose server control properties from a Web User Control?
Hi Todd,
"Todd W" <gladiatori@gladiatori.com> wrote in message
news:3ca4d47c$1@10.1.10.29...
> Does anyone know how to expose the text property of the label in the User
> Control in such a way that the ASPX page it resides on can set the text
property?
> A simple example would be that when the client types in a value in a textbox
> on the web page and then clicks a button, the Label on the User Control has
> its text property set to the text in the text box.
To expose the text property, put the following code (VB) in the user control:
Public MustInherit Class UserLabel
Inherits System.Web.UI.UserControl
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Label1.Text = _Text
End Sub
Private _Text As String = "user control label"
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
Then, assuming you register the user control on the Web page as follows:
<%@ Register tagprefix="sma" tagname="userlabel" Src="UserLabel.ascx"%>
In the ASPX page load, put the following code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim oUserLabel As UserLabel = Me.FindControl("smaUserLabel")
oUserLabel.Text = TextBox1.Text
End Sub
--
Constance Petersen, DevX newsgroup section leader
SoftMedia Artisans, Inc.
http://www.smartisans.com
For useful, usable software and Web sites
Featured Web design: http://www.keweenawnow.com/
--
Please reply in the newsgroup so everyone can benefit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks