RegisterClientScriptBlock does not work from a server control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default RegisterClientScriptBlock does not work from a server control

    For some reason I cannot get RegisterClientScriptBlock to render a script
    reference on the page from a server control. Yes, I have not placed the code
    in the Render method, I also tried the OnInit just in case. Below is the a
    simple version of the code, any help is appreciated:

    namespace MyCompany.Web
    {
    public class Header : System.Web.UI.WebControls.WebControl
    {

    private void RenderClientJavaScript(string javaScriptFilename)
    {
    string script = string.Format(@"<SCRIPT language=""javascript""
    src=""/baxScripts/{0}.js""></SCRIPT>", javaScriptFilename);

    if (! Page.IsClientScriptBlockRegistered(javaScriptFilen ame))
    Page.RegisterClientScriptBlock(javaScriptFilename, script);
    }

    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);
    RenderClientJavaScript("basicToolset");
    RenderClientJavaScript("webMenu");
    }

    protected override void Render(HtmlTextWriter writer)
    {
    writer.Write("Hello World");
    }

    }
    }
    Cameron Eckman Guest

  2. Similar Questions and Discussions

    1. RegisterClientScriptBlock with rendered control?
      Hi, Are there any issues using ClientScriptManager.RegisterClientScriptBlock in a rendered control? I'm calling this function within the...
    2. ClientScript.RegisterClientScriptBlock in ASP.NET 2.0
      I am working on converting my code from ASP.NET 1.1 to ASP.NET 2.0. In ASP.NET 1.1 the RegisterClientScriptBlock method was just a key and script...
    3. Where is Page.RegisterClientScriptBlock Available?
      I have used the RegisterClientScriptBlock method in external functions of mine (ones that are saved in a separate *.vb file), where I use them as...
    4. Where is RegisterClientScriptBlock?? RegisterScripts etc.
      Hello, Where can I find RegisterClientScriptBlock() Page class does not have it. Do I have to Import or add some special reference?? what...
    5. control equivalent to Page.RegisterClientScriptBlock?
      I have a user control that can be created from a variety of other user controls. It is the same no matter where it is created from, and I only...
  3. #2

    Default Re: RegisterClientScriptBlock does not work from a server control

    I would place my money on RenderClientJavaScript not getting called.
    I do not believe the fact that you are not calling base.Render should
    effect the actual rendering of the JavaScript so double check that
    RenderClientJavaScript is actually getting called at the appropriate
    time. You can do this if you are using VS.NET and debugging locally
    simply by placing a breakpoint there and then running the web app in
    debug mode. .

    recoil@community.nospam Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139