Archive for September, 2012

It’s been a while since I’ve used AJAX, but I came across the error “Script control may not be registered before PreRender” when trying to add a timer control to an User Control embedded in a WebPart. I’m pretty certain I have encountered this error before, but as it took me a little while to resolve I thought I’d better blog about it.

What was I trying to do? Well, I was trying to create a Web Part which created a sort of slideshow of web parts! The idea was to use various web parts, which displayed different charts, by loading them dynamically using an Update Panel, a Timer and an AsyncPostBackTrigger. 

At first, things didn’t go to well and I received the error screen shown below

Script control may not be registered before PreRender 

It turns out that the solution is slightly easier that I expected.  Initially, I added a script manager to the user control but, because the timer control automatically posts back the script manager is not loaded when its is looking for it.

So, to resolve the issue, I added the ScriptManager to the SharePoint master page added a ScriptManagerProxy to the user control and it worked a treat.

User Control HTML
  1.   <asp:ScriptManagerProxy ID="ScriptManagerProxy1"runat="server">
  2. </asp:ScriptManagerProxy>
  3. <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="20000">
  4. </asp:Timer>
  5. <asp:UpdatePanel ID="DynamicUpdatePanel" runat="server">
  6.    <Triggers>
  7.         <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
  8.     </Triggers>
  9.     <ContentTemplate>
  10.         <asp:PlaceHolder ID="DynamicPlaceHolder" runat="server"></asp:PlaceHolder>
  11.     </ContentTemplate>
  12. </asp:UpdatePanel>