Events and postback with dynamic ASP.Net user controls

I’ve been trying to build an editable organisation chart for an intranet project and have built up a structure of nested dynamic user controls. This was all working well for displaying the information but wasn’t working so well for posting back and registering events.

A bit of Googling later and I found this article on the 4 Guys From Rolla site called Dynamic Web Controls, Postbacks, and View State which explained the general gist of it.

The cause of the problem was that if you bind the data that loads the controls in page load then the events don’t fire, but if you don’t bind it there’s no data to register the event on. The solution? Do the binding in the init function instead. It worked a treat.

Dynamic Web Controls, Postbacks, and View State

Advertisements
This entry was posted in Programming. Bookmark the permalink.

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