UserControl Property Grid

Discussion in 'ASP .Net' started by margelos@gmail.com, Jan 18, 2007.

  1. Guest

    I have created the following usercontrol

    public class RegisterUser : TemplatedWebControl {


    private VisFields _vfields = new VisFields();
    public VisFields VisibleFields {
    get { return _vfields; }
    set { _vfields = value; }
    }

    private bool _showit;
    public bool ShowIt {
    get { return _showit; }
    set { _showit=value;}
    }

    public RegisterUser() : base() {
    }


    VisFields is a custom class that has properties of boolean
    [TypeConverter(typeof(VisFieldsConverter)), Description("Select Visible
    Fields")]
    public class VisFields {
    private bool _firstQuestion;
    private bool _secondQuestion;

    [DefaultValue(true)]
    public bool FirstQuestion {
    get { return _firstQuestion; }
    set { _firstQuestion = value; }
    }

    [DefaultValue(true)]
    public bool SecondQuestion {
    get { return _secondQuestion; }
    set { _secondQuestion = value; }
    }

    }

    if have of also implemented VisFieldConverter
    public class VisFieldsConverter : ExpandableObjectConverter {
    ..
    ..
    ..
    }

    When i drag and drop the control into my webpage, and click on the
    property grid, i see the (VisibleFields) property and i can expand it
    and see its properties (FirstQuestion,SecondQuestion). I can change
    them to true/false, but when i switch to source of design mode, or even
    when i run the page, these properties always have their default value.
    So the problem is that the control CAN'T keep the changes i make from
    design mode. Any ideas??
    , Jan 18, 2007
    #1
    1. Advertising

  2. If you want to keep the values in the properties, you should use ViewState
    for that.

    public bool SecondQuestion {
    get {
    if(ViewState["SecondQuestion"] != null)
    return
    Convert.ToBoolean(ViewState["SecondQuestion"]);
    return true;
    }
    set { ViewState["SecondQuestion"] = value; }
    }
    It works fine. :)


    <> wrote in message
    news:...
    >I have created the following usercontrol
    >
    > public class RegisterUser : TemplatedWebControl {
    >
    >
    > private VisFields _vfields = new VisFields();
    > public VisFields VisibleFields {
    > get { return _vfields; }
    > set { _vfields = value; }
    > }
    >
    > private bool _showit;
    > public bool ShowIt {
    > get { return _showit; }
    > set { _showit=value;}
    > }
    >
    > public RegisterUser() : base() {
    > }
    >
    >
    > VisFields is a custom class that has properties of boolean
    > [TypeConverter(typeof(VisFieldsConverter)), Description("Select Visible
    > Fields")]
    > public class VisFields {
    > private bool _firstQuestion;
    > private bool _secondQuestion;
    >
    > [DefaultValue(true)]
    > public bool FirstQuestion {
    > get { return _firstQuestion; }
    > set { _firstQuestion = value; }
    > }
    >
    > [DefaultValue(true)]
    > public bool SecondQuestion {
    > get { return _secondQuestion; }
    > set { _secondQuestion = value; }
    > }
    >
    > }
    >
    > if have of also implemented VisFieldConverter
    > public class VisFieldsConverter : ExpandableObjectConverter {
    > .
    > .
    > .
    > }
    >
    > When i drag and drop the control into my webpage, and click on the
    > property grid, i see the (VisibleFields) property and i can expand it
    > and see its properties (FirstQuestion,SecondQuestion). I can change
    > them to true/false, but when i switch to source of design mode, or even
    > when i run the page, these properties always have their default value.
    > So the problem is that the control CAN'T keep the changes i make from
    > design mode. Any ideas??
    >
    Michael Tkachev, Jan 18, 2007
    #2
    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. huobazi
    Replies:
    1
    Views:
    682
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    409
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,539
  4. Fabiano
    Replies:
    2
    Views:
    597
    =?Utf-8?B?c3Jpbmk=?=
    Jun 3, 2005
  5. Rafa³ Ziêba

    Nullable property in property grid

    Rafa³ Ziêba, Jul 3, 2008, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    775
    Rafa³ Ziêba
    Jul 3, 2008
Loading...

Share This Page