I have a composite control that contains a 3rd party tree control. This tree is displaying data that it retrieves from an outside source (over the web). Before using ajax this control would load when the page is refreshed. I'm trying to incorporate ajax now so that this composite control will update itself at a designated interval. The idea is for me to drop this control onto an existing web page and it will update itself while not affecting the main web page using ajax. Sounds good.
Here is what I've done so far - Inside the composite control I've added the UpdatePanel in the CreateChildControls method and added my controls to the UpdatePanel's ContentTemplateContainer:
ScriptManager sMgr = ScriptManager.GetCurrent(Page);if (sMgr ==null || !sMgr.EnablePartialRendering){// If partial rendering is not enabled, set the parent// and container as a basic control.container =new Control();parent = container;}else{// If partial rendering is enabled, set the parent as// a new UpdatePanel object and the container to the // content template of the UpdatePanel object.UpdatePanel up =new UpdatePanel();up.ID ="MyUpdatePanel";Button btn =new Button();btn.ID ="btn";btn.Text ="Refresh";AsyncPostBackTrigger trigger =new AsyncPostBackTrigger();trigger.ControlID ="btn";UpdatePanelTriggerCollection uptc =new UpdatePanelTriggerCollection(up);uptc.Add(trigger);container = up.ContentTemplateContainer;parent = up;}container.Controls.Add(myTree);container.Controls.Add(myTree2);container.Controls.Add(lblStatus);container.Controls.Add(btn);Controls.Add(parent);
When the page loads for the first time, it works correctly, but when I click on the Refresh button, the control refreshes but nothing gets displayed. There is nothing but white space where the tree control was when it first loaded. It's as if its working to grab the new data but not rendering.
Questions:
1. Am I going about using ASP.NET Ajax the right way when using it with Custom Server Controls and Composite Controls? Should I be adding the UpdatePanel to the server control or should I just place it in the hosting web page?
2. If I needed to control the display/rendering of this control how would/should I go about doing that? Before, I overrode the Render method and formatted the display of the control exactly how I wanted. How would I go about doing that when I use the UpdatePanel?
Would love to hear some advice on what I'm missing or doing wrong.
Doug
Anyone run into this kind of problem before?...
No comments:
Post a Comment