-1

I'm using asp.net 4.0. I have access to ClientScriptManager but when I try to type in RegisterClientScriptBlock(), there is no intellisense and I get an error about a static method. I was looking at Response.Redirect() in iFrame, redirect parent window as an example. Apparently there is some difference.

The page I'm on does inherit from System.Web.UI.Page. What is the proper way to use this method?

Community
  • 1
  • 1
4thSpace
  • 43,672
  • 97
  • 296
  • 475

3 Answers3

2

From MSDN

Registers the client script with the Page object using a type, key, and script literal.

Notice it specificly states it works with a Page object.

The Page object has a ClientScript property of type ClientScriptManager and therefore you can use RegisterClientScriptBlock().

If you're inheriting from Page (sorry, missed that part) just use ClientScript.RegisterClientScriptBlock for example:

 protected void Page_Load(object sender, EventArgs e)
 {
        ClientScript.RegisterClientScriptBlock(this.GetType(),"MyMethod","alert(1);", true);
Blachshma
  • 17,097
  • 4
  • 58
  • 72
1

use

ScriptManager.RegisterClientScriptBlock

and dont forget to add a script manager to your page.

writeToBhuwan
  • 3,233
  • 11
  • 39
  • 67
0

You need to call it on ClientScriptManager

Belogix
  • 8,129
  • 1
  • 27
  • 32