This is a migrated thread and some comments may be shown as answers.

[Solved] Dynamic User Controls and jScript

2 Answers 131 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
topry
Top achievements
Rank 1
topry asked on 26 May 2009, 09:41 PM
I have VS2008 webapp that dynamically loads usercontrols.
The masterpage has an instance of RadScriptManager and RadAjaxManager and each control has a RadAjaxManager proxy.
Without enabling Ajax on the master page, everything works properly.

With Ajax enabled on the masterpage everything still works - except the jscript on the 2nd and subsequent loaded usercontrols.  The jscript on the first control loaded works correctly, but controls 2-x return 'undefined' errors on all of the jscript methods contained within the controls. If I change the order of the controls, the first one always works and 2-x do not.

I've read posts about using the ScriptManager.RegisterStartupScript, but some of these controls have a considerable amount of jscript and trying to maintain that within the context of the serverside code as a string isn't feasible, not to mention the debugging issues it presents. Also, while simple jscript functions via .RegisterStartupScript seem to work ok, I am getting null references on any objects that I try and reference (either using $find or document.getElementById('<%=controlID.ClientID%>'); within those usercontrols.

Is it possible to get the jscript within all the usercontrols to work properly when loaded via Ajax?

2 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 30 May 2009, 05:15 AM
Hi Topry,

Unfortunately the provided information is not enough to determine what have caused the unexpected behavior. In order to progress in the resolution of this problem, please open a formal support ticket and send us a simple working project, so we can check it.

Additionally, try placing all script code inside <telerik:RadScriptBlock> controls. This is required so your javascript code is evaluated after ajax requests:

<telerik:RadScriptBlock runat="server">
   <script type="text/javascript">
          //Your JavaScript here
   </script>
</telerik:RadScriptBlock>
 
For more information about loading user controls dynamically, please refer to the following articles:
Load user controls
Demo

Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
topry
Top achievements
Rank 1
answered on 01 Jun 2009, 02:02 PM
Tags
Ajax
Asked by
topry
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
topry
Top achievements
Rank 1
Share this question
or