Inject Script from code-behind

2 posts, 0 answers
  1. Ajay
    Ajay avatar
    42 posts
    Member since:
    Jul 2010

    Posted 12 Jan 2011 Link to this post


    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());

    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.
  2. Simon
    Simon avatar
    2281 posts

    Posted 12 Jan 2011 Link to this post

    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.

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