Mantain Property

M

Mike

Hi,
I don't know how to mantain the value of a Property of my WebCustomControl.
I've my Control and set:
------Code in Page container of contrl ----...
....
if(!IsPostBack)
myControl.DataSource = myDataSource;
myControl.DataTextField = "TextField";
myControl.DataValueField = "ValueField";
.....

------ Code in Contrl -----
.....
public string DataTextField
{
get{return this._dataTextField;}
set{_dataTextField = value;}
}
....

and when PostBack raised the value of this propertys are null :(
I can mantain the value using Session, but is little elegante.

Someone has an example about this?

THANKS!
 
B

Brock Allen

To maintain data in a custom control across postbacks, don't store the data
in a field. Instead store it in ViewState.

public string DataTextField
{
get{
if (ViewState["DataTextField"] == null) return "";
return ViewState["DataTextField"] as string;
}
set{
ViewState["DataTextField"] = value;
}
}
 

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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top