hi i have a WebUserControl that have a lable for show message how can i send a value to the lable from Page to my WebUserControl at runtime.
Asked
Active
Viewed 898 times
0
-
from the page means, you mean code behind file?? – kobe Dec 09 '10 at 07:42
3 Answers
1
In the code behind file of your control you can specify an attribute
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public String customType
{
get
{
String s = (String)ViewState["customType"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["customType"] = value;
}
}
And after you can get this attribute to fill your label in the pageload with
mylabel.text = mycontrol.customType
In the asp page you specify the attribute (here is the 'customType'):
<wuc:ContSign customType="person" ID="ContSignPanel" runat="server" />

bAN
- 13,375
- 16
- 60
- 93
0
You can create a public method in your user control such as
public void ShowMessage(string message)
{
Label1.Text = message;
}
Label1 being the label control in user control. Now you can use the method from Page as and when you need it - for example,
protected void Page_Load(object Sender, EventArgs e)
{
MyUserControl1.ShowMessage("Hello");
}
where MyUserControl1 is the name/ID of web user control put on the page.

VinayC
- 47,395
- 5
- 59
- 72
0
just make a property to get and set values for the lable in the user control
private string _labelmsg;
public string LableMsg
get
{
return _labelmsg;
}
set
{
_labelmsg=lblID.Text;
}
and then set in the aspx.cs page like
UserControlID.LabelMsg="Set Any Value";

sam
- 685
- 7
- 17