Composite Web Control - RegisterClientScriptBlock Not Written

S

Simon Harris

Hi All,

I'm trying to write a composite web control which will render a rich text
editor.

I am having problems with RegisterClientScriptBlock - The script simply
doesnt get written. There are no errors compiling the code. Strangly, if I
use RegisterClientScriptBlock, the script gets written to the page, but
the
script is then in the wrong place - The script gets run before the page is
rendered.

Heres the relevent chunk of my code:

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
'Javascript
Dim strJSScriptKey As String = "RichEditorJS"
If Page.IsClientScriptBlockRegistered(strJSScriptKey) = False Then
strJavascript =
GetFileContents(HttpContext.Current.Server.MapPath("/richeditorfiles") &
"/richeditor.js")
Page.RegisterClientScriptBlock(strJSScriptKey, "<script
language=javascript>alert('Woot');</script>")
End If

'VBScript
Dim strVBSScriptKey As String = "RichEditorVBS"
If Page.IsClientScriptBlockRegistered(strVBSScriptKey) = False
Then
strVBScript =
GetFileContents(HttpContext.Current.Server.MapPath("/richeditorfiles") &
"/richeditorvbs.txt")
Page.RegisterClientScriptBlock(strVBSScriptKey, "<script>" &
strVBScript & "</script>")
End If



I have read something about using PreRender - The article wasnt entirely
relevent, and didnt give an example, but PreRender sounded perhaps useful?

Thanks!

Simon.
 
S

Simon Harris

Solved it, works Ok when I put the code to register the script blocks in
the
OnPreRender event

Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top