Data postback in custom controls

I have spent around 3 hours today debugging a custom control which was required to capture simple text.  The problem was that whatever I entered in the text box was not being persisted after a post back. I tried the following during the time:

  • Use FindControl to resolve member variable controls – failed
  • Change CreateChildControls method to create only if  not Page.IsPostBack – failed, worse – controls were not rendered after post back
  • Use a static method for performing my logic and use Page.FindControl in that method – failed.
  • Save control tree to ViewState – failed, TextBox is not serializable
  • Use WebControl instead of Panel as base class, and use [PersistChildren(true)] – failed. No effect.
  • Use CompositeControl instead of WebControl  and use [PersistChildren(true)] – worked!
  • Use CompositeControl without [PersistChildren(true)] worked!
Advertisements

About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: