Control

S

shapper

Hello,

I created a user control where I have two controls: Button and Image.

How can I "expose" these two controls properties and events so I can
access them in the C# / VB.NET code of the page where I use the user
control?

Thanks,
Miguel
 
G

Guest

Howdy,

public partial class MyUserControl : System.Web.UI.UserControl
{
.....
public Button MyButton
{
get
{
return this.myButtonInstance;
}
}

public Image MyImage
{
get
{
return this.myImageInstance;
}
}
....

}

And then you may use their properties both declaratively:

<uc1:MyUserControl runat="server" ID="myUserControlInstance"
MyButton-Text="Blabla" MyButton-OnClientClick="alert('howdy!'); return true;"
MyImage-ImageUrl="~/images/sunset.jpg"/>

or/and programatically:

myUserControlInstance.MyButton.Text = "Well well well, we meet again...";
myUserControlInstance.MyImage.ImageUrl = "~/images/picture.gif";

Ussualy it's good to expose useful properties only (of course if possible),
not everything you have in internal controls i.e.

public string UserImageUrl
{
get
{
return this.myImageInstance.ImageUrl;
}
set
{
this.myImageInstance.ImageUrl = value;
}
}

Hope this helps
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top