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

Inject Script from code-behind

1 Answer 101 Views
ScriptManager and StyleSheetManager
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 12 Jan 2011, 10:56 AM
Hi,

I want to inject some JavaScript code into the aspx page (on some server side event). But the script doesn't get rendered on the page.
I have RadScriptManager on the MasterPage, and RadScriptBlock on the ContentPage.

Then I wrote below code , but it didn't worked:
StringBuilder sb = new StringBuilder();
sb.Append("<script>alert('script test')</script>");
LiteralControl script = new LiteralControl(sb.ToString());
RadScriptBlockCP.Controls.Add(script);

I also tried below code but failed:
String scriptContent = "script type=\"text/javascript\" language=\"javascript\">alert('test alert')</script>";
(RadScriptBlockCP.Controls[0] as LiteralControl).Text = scriptContent;

Please help.

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 12 Jan 2011, 11:08 AM
Hello Ajay,

RadScriptBlock is used to allow loading of scripts with AJAX. Is this your case?

If not, I suggest you just add the Literal to the page's controls collection.

Greetings,
Simon
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
ScriptManager and StyleSheetManager
Asked by
Ajay
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or