find child control

J

Jon Paal

i have a textbox control inside a custom server control that needs to be prefilled with content.

how do i find this child control ?


<ew:cp id="ccp2" TitleText="" runat="server">
<asp:TextBox id=TB1" runat="server" />
</ew:cp>
 
M

Mark Fitzpatrick

Your best bet may be to expose the text property of the textbox instead. You
would do this as a property for the control such as:

public string TextBoxText
{
get
{
return TB1.Text;
}
set
{
TB1.Text = value;
}
}

I've found that this works nicer than trying to find controls since you
don't have to worry about testing for null values.
 
J

Jon Paal

i have no way of using that type of coding.

what's the vb inline code equivalent of this ?


sub page_load()
public string TextBoxText
{
get
{
return TB1.Text;
}
set
{
TB1.Text = value;
}
}
End sub
 
M

Mark Fitzpatrick

Jon,
It's just a property definition. In VB it would be:

Public Property TextBoxText() As String
Get
Return TB1.Text
End Get
Protected Set(ByVal value As String)
TB1.Text = value
End Set
End Property

You define this in the user control. It's not to be placed within any other
function such as page_load. It's considered a function by itself. To set it,
you would use
sub page_load()
ccp2.TextBoxText = "some text"
End sub

within the page that contains the usercontrol it.


--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top