UserControl Property Grid

M

margelos

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??
 
M

Michael Tkachev

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. :)
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top