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

Add javascript from code behind

3 Answers 223 Views
ScriptManager and StyleSheetManager
This is a migrated thread and some comments may be shown as answers.
Benny
Top achievements
Rank 1
Benny asked on 22 Jul 2009, 09:37 AM
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?

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Jul 2009, 01:07 PM
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.
0
Benny
Top achievements
Rank 1
answered on 22 Jul 2009, 01:46 PM
I already tried that, but then I can't use the jQuery parts that is used by Telerik :-(

0
Atanas Korchev
Telerik team
answered on 22 Jul 2009, 01:51 PM
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.
Tags
ScriptManager and StyleSheetManager
Asked by
Benny
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Benny
Top achievements
Rank 1
Share this question
or