Groups | Blog | Home
all groups > asp.net building controls > march 2006 >

asp.net building controls : ASP.Net 2.0: Help with ClientScriptManager


Rory Clark
3/30/2006 8:52:54 AM
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
4/19/2006 2:15:02 AM
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.



[quoted text, click to view]
AddThis Social Bookmark Button