ASP.Net 2.0: Help with ClientScriptManager

Discussion in 'ASP .Net Building Controls' started by Rory Clark, Mar 30, 2006.

  1. Rory Clark

    Rory Clark Guest

    I'm working on a custom control that needs to register client script to the
    page.

    string key = "ScriptKey";
    string script = "<script language=\"javascript\"> alert('Hi'); </script>";
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), key, script,
    false);

    The code executes, but no script is rendered to the page. Is there
    something I'm missing here?

    I've tried moving this around even, including RenderControl(), OnLoad(),
    OnPreRender(), and OnInit().

    Thanks!
     
    Rory Clark, Mar 30, 2006
    #1
    1. Advertising

  2. Rory Clark

    Sebastian Guest

    Hi Rory,

    try:
    if (!this.IsClientScriptBlockRegistered("clientScript"))
    {
    your script made with StringBuilder

    this.RegisterClientScriptBlock("clientScript",
    yourStringBuilder.ToString());
    }

    It works on my page. Hope it helps.



    "Rory Clark" wrote:

    > I'm working on a custom control that needs to register client script to the
    > page.
    >
    > string key = "ScriptKey";
    > string script = "<script language=\"javascript\"> alert('Hi'); </script>";
    > Page.ClientScript.RegisterClientScriptBlock(this.GetType(), key, script,
    > false);
    >
    > The code executes, but no script is rendered to the page. Is there
    > something I'm missing here?
    >
    > I've tried moving this around even, including RenderControl(), OnLoad(),
    > OnPreRender(), and OnInit().
    >
    > Thanks!
    >
    >
    >
     
    Sebastian, Apr 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5kcsOp?=

    ClientScriptManager.RegisterForEventValidation

    =?Utf-8?B?QW5kcsOp?=, Nov 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,911
  2. stewart
    Replies:
    2
    Views:
    14,431
    stewart
    Dec 7, 2005
  3. n33470
    Replies:
    9
    Views:
    151,599
    AbercrombieLV
    May 30, 2010
  4. Lloyd Dupont

    ClientScriptManager without a page...

    Lloyd Dupont, Jan 29, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,458
    luckyhuss
    Sep 1, 2006
  5. DNB
    Replies:
    2
    Views:
    1,815
    Michael Nemtsev
    Dec 13, 2007
Loading...

Share This Page