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

Custom Client script in User Control loaded by callback method

2 Answers 117 Views
XmlHttpPanel
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 26 Jan 2010, 11:20 PM
I have an XmlHttpPanel that I am loading a User Control into by the callback method.  I have a RadScriptBlock inside the user control.  This code does not get evaluated even though I have the XmlHttpPanel.EnableClientScriptEvaluation=True.  How do I include control level client script to be evaluated after a callback?

I know Telerik does it somehow because my control has a RadComboBox that has OnClientIndexChanged set to my Custom Client Script and when the Init is run on the combobox it can't find the function.  The init function is in the same callback response as my custom script.  It works but my script does not.  It doesn't make sense to me.

Thanks,
Doug

2 Answers, 1 is accepted

Sort by
0
Doug
Top achievements
Rank 1
answered on 27 Jan 2010, 07:52 PM
UPDATE: I have found that if the contents of the RadScriptBlock does not have server tags <%=ServerControl.ClientID%> then the javascript is evaluated on the client correctly.  I also found that the RadScriptBlock1.Controls.Count = 1 and RadScriptBlock1.Controls(0).Text contains the script when there are no server tags.  If there are server tags RadScriptBlock1.Controls.Count = 0.

Just more clues to the problem.
0
Accepted
Pero
Telerik team
answered on 29 Jan 2010, 03:08 PM
Hi Doug,

The XmlHttpPanel receives a string containing the HTML that will be pasted within the panel. If this HTML starts with a <script> or <style> tag, these (<script> and <style>) elements will be stripped by the browser and the content will actually start from the first non-<script> (or non-<style>) element. Basically if you have placed your client-script right at the top of the UserControl's markup, the script will never be evaluated because it is not there (it has been removed by the browser). To avoid this behavior you can place the client-script at the bottom of the UserControl, or you can place a hidden <input> just before the <script> tag. For your convenience I have attached a sample project showing how to achieve this. You will notice that everything works fine and the scripts are evaluated.


Sincerely yours,
Pero
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
XmlHttpPanel
Asked by
Doug
Top achievements
Rank 1
Answers by
Doug
Top achievements
Rank 1
Pero
Telerik team
Share this question
or