Add javascript from code behind

4 posts, 0 answers
  1. Benny
    Benny avatar
    33 posts
    Member since:
    May 2009

    Posted 22 Jul 2009 Link to this post

    Hi,
    I'm trying to add a generated JQuery-script with the RadScriptManager but I can't figure out how...
      // Type cstype = GetType(); 
            // const string csname = "GroupLabelScript"; 
            // ClientScriptManager cs = Page.ClientScript; 
     
            StringBuilder script = new StringBuilder(); 
     
            script.AppendFormat("<script type=\"text/javascript\">{0}", Environment.NewLine); 
     
            script.AppendFormat("{0}",Environment.NewLine); 
     
            script.AppendFormat("$telerik.$(document).ready(function() {0} {1}", @"{", Environment.NewLine); 
            for (int i = 0; i < (7 * 3); i++) 
            { 
                script.AppendFormat("$telerik.$(\".rsHorizontalHeaderTable tr:last th:eq({0})\").addClass(\"{1}\");{2}", i, (i % 2 == 0) ? "Red" : "Green", Environment.NewLine); 
            } 
            script.AppendFormat("{0});{1}", @"}", Environment.NewLine); 
            script.Append(Environment.NewLine); 
     
            script.AppendFormat("</script>{0}", Environment.NewLine); 
     
            // How do I add my script to the RadScriptManager1 ?! 
            RadScriptManager1.Scripts.Add(script.ToString()); 
             
            // cs.RegisterClientScriptBlock(cstype, csname, script.ToString(), false); 

    This " RadScriptManager1.Scripts.Add(script.ToString());" does of cource not work... But how do I do what I'm trying to do?

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 22 Jul 2009 Link to this post

    Hi BEnny,

    You can use the RegisterClientScriptBlock method in order to register JavaScript blocks. To register JavaScript code that shall be executed when the page is loaded you should use the RegisterStartupScript method.

    Regards,
    Albert
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Benny
    Benny avatar
    33 posts
    Member since:
    May 2009

    Posted 22 Jul 2009 Link to this post

    I already tried that, but then I can't use the jQuery parts that is used by Telerik :-(

  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 22 Jul 2009 Link to this post

    Hello BEnny,

    I am not sure what you mean. Please clarify what jQuery parts do not work when you are using that approach. I recommend you open a support ticket and send us your test page. We will see what is wrong and provide a solution.

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