RegisterClientScriptBlock to register OUTSIDE form tags

W

Wes Weems

Hello,

I currently have javascript and vbscript that needs to be spat out based on
certain conditions in the codebehind. My vbscript code relies on the OnLoad
event. However with the RegisterClientScriptBlock(), sticking the code in
the form tags, I cant seem to get the bastard to work.


Basically heres what I *NEED* to do. Generate some js and vbscript to be
output before or after the form tags.

I tried defining the variables in the codebehind with the protected
modifier... then setting them in Page_Load... and then doing <%=myVar%> and
nothing gets spat out to the browser.

If anyone could *PLEASE* give me any words of wisdom, they would be greatly
appreciated.

Wes
 
K

Ken Cox [Microsoft MVP]

Hi Wes, you might find that RegisterStartupScript does what you need since it
runs on load or thereabouts.

In your code behind:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim strName As String = "Wes"
RegisterStartupScript("start", _
"<script>sayHello('Hello " & strName & "');</script>")
End Sub

' In your .aspx page:

<script language="javascript">
function sayHello(strMsg) {
alert(strMsg);
}
</script>

Ken
MVP [ASP.NET]


Hello,

I currently have javascript and vbscript that needs to be spat out based on
certain conditions in the codebehind. My vbscript code relies on the OnLoad
event. However with the RegisterClientScriptBlock(), sticking the code in
the form tags, I cant seem to get the bastard to work.


Basically heres what I *NEED* to do. Generate some js and vbscript to be
output before or after the form tags.

I tried defining the variables in the codebehind with the protected
modifier... then setting them in Page_Load... and then doing <%=myVar%> and
nothing gets spat out to the browser.

If anyone could *PLEASE* give me any words of wisdom, they would be greatly
appreciated.

Wes
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top