Custom Client script in User Control loaded by callback method

3 posts, 1 answers
  1. Doug
    Doug avatar
    23 posts
    Member since:
    Feb 2009

    Posted 26 Jan 2010 Link to this post

    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.

  2. Doug
    Doug avatar
    23 posts
    Member since:
    Feb 2009

    Posted 27 Jan 2010 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Answer
    Pero avatar
    1156 posts

    Posted 29 Jan 2010 Link to this post

    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,
    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.
Back to Top