Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maintaining State in a web control library.

Status
Not open for further replies.

JustBarno

Programmer
Jun 21, 2004
46
0
0
US
I have a web control library that I've recently finished developing. However, I'm having a problem maintaining state. I have the following code

If not ispostback then
ctrl.Property1 = x
ctrl.Property2 = y
ctrl.Main() 'runs the business logic and sets the [text] property
end if

The code works fine to generate my control the first time the page is loaded, but despite enableviewstate being set to true. It loses state on any postback. Is there some process that I need to follow to enable that functionality in the control code?

Thanks!

-Justin
 
Yes. You need to have your properties explicitly use ViewState (or devise a custom method of saving/loading ViewState).

This is the easy way:


//in your control
public string Property1
{
get
{
Object o = ViewState["Prop1"];
return ( o == null ? String.Empty : (string)o );
}
set
{
ViewState["Prop1"] = value;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top