Setting a Property on a User Control

J

joer.banno

Hi

I have a table with 2 columns, one column is a Catalogpartzone and
another a webpartzone:

I have a UserControl which only contains a label, this label has a
public property.

private string _SmurfText;

[Personalizable(PersonalizationScope.User)]
public string SmurfText
{
get
{
return this._SmurfText;
}
set
{
this._SmurfText = value;
}
}


This property is checked on page_load event and if it has been set it
will display the value in the label, else it will display a default
value in the label.

protected void Page_Load(object sender, EventArgs e)
{
if (this.SmurfText != null)
{
this.SmurfMe.Text = this.SmurfText;
}
else
{
this.SmurfMe.Text = "Text not set!";
}
}

The label is added to Declarative part of the catalog zone with a
value for the public property,.

<asp:DeclarativeCatalogPart ID="Declarative1" runat="server">
<WebPartsTemplate>
<LabelSmurf:LabelSmurf
id="RedSmurf" runat="server" visible="true" SmurfText="RedSmurf"/>
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>

now when i Add the userwebpart in catalog mode to the webpartzone, the
default text shows, when I add another the new one shows a default
text and the first one added shows the actual value set in the
usercontrol.

How can I pass the value to the usercontrol so that it will be set the
first time, and not on later requests?
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top