Setting a Property on a User Control

Discussion in 'ASP .Net' started by joer.banno@gmail.com, Jul 3, 2008.

  1. Guest

    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?
     
    , Jul 3, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amir Eshterayeh

    Error Setting user control property at web form

    Amir Eshterayeh, Nov 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    556
    Amir Eshterayeh
    Nov 27, 2003
  2. Karl Lang
    Replies:
    2
    Views:
    326
    Karl Lang
    Jun 17, 2004
  3. Nathan Sokalski
    Replies:
    25
    Views:
    1,481
    Nathan Sokalski
    Mar 4, 2010
  4. Amir Eshterayeh

    Error Setting user control property at web form

    Amir Eshterayeh, Nov 27, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    196
    Teemu Keiski
    Nov 27, 2003
  5. Dave

    Setting user control property dynamically?

    Dave, May 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    150
    Natty Gur
    May 28, 2004
Loading...

Share This Page