Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RegisterClientScriptBlock

0 views
Skip to first unread message

John O'Connell

unread,
Jan 22, 2002, 4:22:38 PM1/22/02
to
What is the purpose of the Page.RegisterClientScriptBlock method? Can
anyone supply some sample code

TIA

John O'Connell


Ken Cox [Microsoft MVP]

unread,
Jan 22, 2002, 5:01:15 PM1/22/02
to
It inserts client-side script into your page. There are a few related
methods that insert script inside a <form> tag and at the end of a page.

For more:

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWebUIPageClassRegisterClie
ntScriptBlockTopic.htm

Ken
MVP [ASP.NET]


"John O'Connell" <ltj__...@hotmail.com> wrote in message
news:uEL1cs4oBHA.2448@tkmsftngp04...

Bertrand Le Roy

unread,
Jan 23, 2002, 5:09:55 AM1/23/02
to
It's particularly important when building a webcontrol that uses client-side
script: if you have two instances of the same control, the script block only
gets added once to the page.

"John O'Connell" <ltj__...@hotmail.com> wrote in message
news:uEL1cs4oBHA.2448@tkmsftngp04...

John O'Connell

unread,
Jan 24, 2002, 4:33:58 PM1/24/02
to
I tried that but didn't get anywhere with it.

"Ken Cox [Microsoft MVP]" <BANSPAM...@sympatico.ca> wrote in message
news:O#OMsA5oBHA.1596@tkmsftngp07...

John O'Connell

unread,
Jan 24, 2002, 6:18:16 PM1/24/02
to
Well here's my code in the PageLoad handler:

private void Page_Load(object sender, System.EventArgs e)
{
Page.RegisterClientScriptBlock("mykey", "alert(\"hi\")");
}

It didn't work - no script was emitted in the generated web page. I've also
tried a literal <script> tag but no joy. Any ideas? Or is this NYI in Beta
2?

John

"Ken Cox [Microsoft MVP]" <BANSPAM...@sympatico.ca> wrote in message
news:O#OMsA5oBHA.1596@tkmsftngp07...

Ken Cox [Microsoft MVP]

unread,
Jan 28, 2002, 9:20:19 AM1/28/02
to
You forgot the script tags:

Page.RegisterClientScriptBlock("mykey", "<script>alert(\"hi\")</script>");

Ken
MVP [ASP.NET]

"John O'Connell" <ltj__...@hotmail.com> wrote in message

news:O1Bff2SpBHA.2232@tkmsftngp02...

John O'Connell

unread,
Jan 28, 2002, 5:18:25 PM1/28/02
to
Tried that, no joy. Any other suggestions? :-))

John

"Ken Cox [Microsoft MVP]" <BANSPAM...@sympatico.ca> wrote in message

news:#YiAzaAqBHA.2212@tkmsftngp04...

Ken Cox [Microsoft MVP]

unread,
Jan 28, 2002, 6:44:19 PM1/28/02
to
This is strange because it works for me. What error message do you get when
compiling? Can anyone else verify this code? It just throws up an alert.

Anyway, here's the content of my startup.aspx.cs file.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace p450_cs_work
{
/// <summary>
/// Summary description for startup.
/// </summary>
public class startup : System.Web.UI.Page
{


private void Page_Load(object sender, System.EventArgs e)
{
Page.RegisterClientScriptBlock("mykey",

"<script>alert(\"hi\")</script>");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

"John O'Connell" <ltj__...@hotmail.com> wrote in message

news:#BfY2nEqBHA.2540@tkmsftngp04...

Ken Cox [Microsoft MVP]

unread,
Jan 28, 2002, 6:45:30 PM1/28/02
to
BTW, my code is using the release version. I don't know about when this
might have been introduced.

Ken

"John O'Connell" <ltj__...@hotmail.com> wrote in message

news:#BfY2nEqBHA.2540@tkmsftngp04...

John O'Connell

unread,
Jan 29, 2002, 6:12:32 PM1/29/02
to
Thanks for that, yeah I guess that method is NYI in beta 2 because my code
is as simple and similar that which you presented.

John


"Ken Cox [Microsoft MVP]" <BANSPAM...@sympatico.ca> wrote in message

news:#jsomWFqBHA.2332@tkmsftngp03...

0 new messages