web user controls and placeholders

  • Thread starter cyndie woodster via DotNetMonster.com
  • Start date
C

cyndie woodster via DotNetMonster.com

i had created a web user control named "uscItems.ascx"
and a web form named "pkg.aspx"

i added placeholder in "pkg.aspx" then in load_page i wrote this code

dim usc1 as UserControl=LoadControl("uscItems.ascx")
Me.PlaceHolder1.Controls.Add(usc1)

inside my "uscItems.ascx" there r few components:image,label,checkbox
then now i would like to change the label's text, how can i access to my
user control components???

thanks

cyndie
 
G

Guest

As long as they are server control's, marked with a runat="server" and a
valid ID then you can access them via usc1.FindControl(s).
You could also set up public properties on usc1 that modify the text. This
is probably the preferred method and will also be a bit faster.
In your uscItems.ascx.cs you would just define
public String LabelCaption
{
get { return MyLabelControl.Text; }
set { MyLabelControl.Text = value; }
}
Then you could just go usc1.LabelCAption = "...."; Just remember that the
control you are modifying has to have a runat="server" tag along with a
valid ID and should also have a variable declaration in your code behind if
the Designer did not automagically put it there already. (switching from
design view to code) and vice versa usually triggers vs.net to automagically
add it.


Some sample C# code but easily adaptable to whatever .NET langauge you are
using.
the
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top