ASP.Net 2.0: Help with ClientScriptManager

R

Rory Clark

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!
 
S

Sebastian

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top