473,395 Members | 1,675 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.

How to use <script> tag in code-behind?

hb
Hi,

I need to assign javascript code dynamically to this tag in <head> section.
Would you please tell me how to use <script> tag in code behind?

Thank you

hb
Nov 18 '05 #1
2 2492
You can place a asp:literal control in the head section of your page. then
in code you can say:

<head>
<asp:literal id="dynScript" runat="server" />
</head>

CodeBehind:
Sub Page_Load()
dynScript.text = "<script>alert('hello');</script>"
End Sub
"hb" wrote:
Hi,

I need to assign javascript code dynamically to this tag in <head> section.
Would you please tell me how to use <script> tag in code behind?

Thank you

hb

Nov 18 '05 #2
You specifically said you wanted it in the <head> section, however if
you simply want to make the script available to the web page it doesn't
have to go there it can go just about anywhere in the page. If this
will work for you, ASP.Net provides two methods of the page object to
add scripts to the client: RegisterClientScriptBlock and
RegisterStartupScript. Take a look at these and see if they work for
you. If this won't work for you then the literal is the way to go.

Have A Better One!

John M Deal, MCP
Necessity Software

Tampa .NET Koder wrote:
You can place a asp:literal control in the head section of your page. then
in code you can say:

<head>
<asp:literal id="dynScript" runat="server" />
</head>

CodeBehind:
Sub Page_Load()
dynScript.text = "<script>alert('hello');</script>"
End Sub
"hb" wrote:

Hi,

I need to assign javascript code dynamically to this tag in <head> section.
Would you please tell me how to use <script> tag in code behind?

Thank you

hb

Nov 18 '05 #3

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

Similar topics

1
by: Grzegorz ¦lusarek | last post by:
Hello everyone. I1m writing webb aplication using AJAX (prototype library: http://prototype.conio.net/ and scriptacuolous:http://script.aculo.us/). My Problem is that that I'm doing...
1
by: andrew | last post by:
So I spent ages trying to work out what the problem was with my code when I did this and found a post which led me to the very simple solution. I use WebMatrix so I'm not sure if this is a major...
21
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript"...
12
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
2
by: boczek | last post by:
Hello all. I'm writing a small async webapp. in JavaScript and I'm using <script> element technique to load data. I'm usign <scriptbecause of cross domain restrictions with XmlRequest. The...
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
7
by: gsherp | last post by:
Is there any way to dynamically change what script included in the HTML? <span id="changeit"><script src="test1.js"></script></span> <input type="button"...
7
by: labmonkey111 | last post by:
I'm having trouble with the following code: <SCRIPT> <!-- if (navigator.appName == 'Microsoft Internet Explorer') { document.write("<link rel=\"stylesheet\" type=\"text/css\"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.