Monday, April 21, 2008

Templated User Controls

I just wanted to get this down while it's still fresh in my mind, and hopefully it will help someone else out if they run into the same problem ... Ok, so I created a template user control (called "SidePanelContainer") with the only intention for it to be a formatting thing (basically a bunch of nested divs to create a border, a title and whether to show a close button). Inside the template can go other user controls, web controls, etc. In this instance, I was adding another user control into this templated user control. So it looked something like this in the aspx page ...



<uc1 : sidepanel id='Sidepanel1' runat='server' headertext='HEADER TEXT'>
<sidepaneltemplate>
<uc2>MY DATA USER CONTROL</uc2>
</sidepaneltemplate>
</uc1 : sidepanel>


Upon postback, I was losing the information in the child user control (uc2). To make a lot of code short, I had a Page_Load method in my SidePanelContainer user control that called the DataBind() method. Looking back, that was unnecessary, and it was the source of frustration since my internal user control would rebind each time. I don't know if this will effect actual databound controls, but that's for another day.