473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

RegisterClientScriptBlock to register OUTSIDE form tags

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
Nov 17 '05 #1
1 2292
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]
"Wes Weems" <ww**********@charter.net> wrote in message
news:vh************@corp.supernews.com...
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MW | last post by:
I am trying to register the follow script through the RegisterClientScriptBlock method. When the page loads it tells me that the line contain <script language=javascript> is expect ;. Why would...
0
by: Big Dave | last post by:
Good morning. I'm trying to register a client script block from a server control. I've put the line of code to register it in the render method, the onprerender event, I've overridden the...
0
by: pealy2 | last post by:
A quick pointer to anyone struggling with the RegisterClientScriptBlock function, unless you already have a <FORM> section in your page then the script will not be added. I use vb code to...
3
by: Steve Powell | last post by:
Hi, Can anyone help me with this one? How can I remove script registered by RegisterClientScriptBlock ? If I add another script with the same name, is the first one overwritten or it's just...
1
by: Simon Harris | last post by:
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...
3
by: Paul D. Fox | last post by:
I'd like to modularize my code and I like using the "RegisterClientScriptBlock()" routine. However, I need to have a piece of JavaScript registered at the end of the HTML form. My only...
2
by: kewl | last post by:
Hi All, We have an ASP.NET 2.0 (C#) intranet application that needs to spawn multiple browsers using RegisterClientScriptBlock. Here's what we got so far: // Go thru each datarow in the...
2
by: Alex Maghen | last post by:
Hi. Two questions about "RegisterClientScriptBlock": 1. I want to be able to insert a script block without having to worry about whether the "key" is unique. As it turns out, if a script block...
2
by: Scott M. | last post by:
The following code (VS 2008) does cause the script string to render, but it doesn't render inside of <scripttags, instead the result is rendered just after the opening <formtag, but outside of the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.