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. Advertisements

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:
    644
    Amir Eshterayeh
    Nov 27, 2003
  2. Karl Lang
    Replies:
    2
    Views:
    378
    Karl Lang
    Jun 17, 2004
  3. Mad Scientist Jr
    Replies:
    0
    Views:
    906
    Mad Scientist Jr
    Mar 22, 2006
  4. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    812
    Jonathan Wood
    Feb 2, 2010
  5. Nathan Sokalski
    Replies:
    25
    Views:
    1,857
    Nathan Sokalski
    Mar 4, 2010
  6. Amir Eshterayeh

    Error Setting user control property at web form

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

    Setting user control property dynamically?

    Dave, May 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    199
    Natty Gur
    May 28, 2004
  8. Amir Eshterayeh

    Error Setting user control property at web form

    Amir Eshterayeh, Nov 27, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    230
    Teemu Keiski
    Nov 27, 2003
Loading...