473,761 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to insert JavaScript code dynamically...

Hi all...

I need to add some JavaScript code that is dynamically generated to some
point of the page.

Currently I'm using
ClientScript.Re gisterStartupSc ript(GetType(), "menu", "<script
type=\"text/javascript\">" + oMenu.BuildMenu (true, true, true) + "</script>");

But the script is added to the end of the page, but I need it to be added at
the begining of the page (after <BODY> tag).

How can I do it?
Thanks

Jaime
Nov 19 '05 #1
4 2242
Javascript can be run from any point on the page no matter where it is, so I
don't see why placement of it would be of any importance.

What I would do is place a Literal ASP Web Control right below where you
want to place it and then in the codebehind do this:
this.litJavaScr ipt.Text = "<script
type=\"text/javascript\">Ja vascript</script>";

Hope that helps,

Jason Lind
"Jaime Stuardo" wrote:
Hi all...

I need to add some JavaScript code that is dynamically generated to some
point of the page.

Currently I'm using
ClientScript.Re gisterStartupSc ript(GetType(), "menu", "<script
type=\"text/javascript\">" + oMenu.BuildMenu (true, true, true) + "</script>");

But the script is added to the end of the page, but I need it to be added at
the begining of the page (after <BODY> tag).

How can I do it?
Thanks

Jaime

Nov 19 '05 #2
Jaime,

You could use Page.RegisterCl ientScriptBlock instead, but I don't think that
will always insert the script where you want it either. Why does the script
need to go just after the body tag? Knowing that, there may be some other
solution to your problem.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jaime Stuardo" <Ja**********@d iscussions.micr osoft.com> wrote in message
news:95******** *************** ***********@mic rosoft.com...
Hi all...

I need to add some JavaScript code that is dynamically generated to some
point of the page.

Currently I'm using
ClientScript.Re gisterStartupSc ript(GetType(), "menu", "<script
type=\"text/javascript\">" + oMenu.BuildMenu (true, true, true) +
"</script>");

But the script is added to the end of the page, but I need it to be added
at
the begining of the page (after <BODY> tag).

How can I do it?
Thanks

Jaime

Nov 19 '05 #3
Hi Jaime,

One way to put Javascript code in specified position is to have a Label
control in the position, then assign its Text as Javascript code.

HTH

Elton Wang

"Jaime Stuardo" wrote:
Hi all...

I need to add some JavaScript code that is dynamically generated to some
point of the page.

Currently I'm using
ClientScript.Re gisterStartupSc ript(GetType(), "menu", "<script
type=\"text/javascript\">" + oMenu.BuildMenu (true, true, true) + "</script>");

But the script is added to the end of the page, but I need it to be added at
the begining of the page (after <BODY> tag).

How can I do it?
Thanks

Jaime

Nov 19 '05 #4
In this case, placing the JavaScript anywhere on the page can have differents
results.

That javascript I want to embed in the page is only a function call that
draws a DHTML menu (programmed by a third party). The menu is drawn where
that function is called, using relative positioning

In the current scenario I have:

<form id="frmMain" runat="server">
<div>
<div style="z-index: 101; left: 0px; width: 100%; position: static;
overflow: visible; border-top-width: 5px; border-left-width: 5px;
border-left-color: green; border-bottom-width: 5px; border-bottom-color:
green; border-top-color: green; border-right-width: 5px; border-right-color:
green;">

SOME CONTENT

</div>
</div>
</form>

If I use RegisterStartup Script, the script is placed just before the closing
</form> tag. That causes the menu to appear after "SOME CONTENT". I need it
to be placed before it, so it would be sufficient if if is placed just after
the first <div> tag.

I hope it's clear now why I need to place a JavaScript code in a specific
location.

Jaime

"Jason L Lind" wrote:
Javascript can be run from any point on the page no matter where it is, so I
don't see why placement of it would be of any importance.

What I would do is place a Literal ASP Web Control right below where you
want to place it and then in the codebehind do this:
this.litJavaScr ipt.Text = "<script
type=\"text/javascript\">Ja vascript</script>";

Hope that helps,

Jason Lind
"Jaime Stuardo" wrote:
Hi all...

I need to add some JavaScript code that is dynamically generated to some
point of the page.

Currently I'm using
ClientScript.Re gisterStartupSc ript(GetType(), "menu", "<script
type=\"text/javascript\">" + oMenu.BuildMenu (true, true, true) + "</script>");

But the script is added to the end of the page, but I need it to be added at
the begining of the page (after <BODY> tag).

How can I do it?
Thanks

Jaime

Nov 19 '05 #5

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

Similar topics

6
1862
by: KKramsch | last post by:
OK, here's the scenario: I have a CGI script that generates a page with frames (BTW, I'm not crazy about frames, but in this case the decision to use them is out of my hands). In a typical session, the user interacts with two of these frames extensively, and up to the very end of the session, this interaction is handled entirely client-side by a fairly elaborate JavaScript script. (This interaction takes place exclusively via HTML...
4
6318
by: Sergio del Amo | last post by:
i, I have the next html page <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a href=\"fadfaf\">anchor</a>blalbababa</span>"
3
13472
by: Vic Sowers | last post by:
I'm trying to sort an HTML table (tBody) on one of its columns dynamically. My approach is to remove all the rows into an array, sort the array, and insert to rows back into the tBody. But, there doesn't seem to be any way to insert a pre-existing row into a table (tBody). I've tried inserting a blank row and replacing it with the saved row, but this fails as well. I know about tBody.moveRow(from,to) (this works) but I have to sort the...
4
1452
by: google | last post by:
Hi Heres how the following code works. A user selects a number from a listbox, and then javascript generates that many textboxes. ie. If a user selects 5 from the listbox, then 5 text boxes will appear. Problem is, javascript blanks the page out first. We really need the textboxes to appear underneath the listbox, instead of clearing the screen first. <head>
4
1814
by: cotton_gear | last post by:
Hello, I need to add some javascript code block dynamically to a web page. I looked into the various postings at various groups but none seems to be solving my problem. Among the approaches suggested first one is to create a script element and set its properties (src etc) and then adding this script element to the head element. This works good for a dynamically including the files. But, in my case
0
1294
by: MS News \(MS LVP\) | last post by:
Hello, From a user control what is the best way ( other than static ) to insert JavaScript include in the Head of an HTML page <head> <script language='javascript' src="myPamela.js"></script> </head> I have no control of the Main page where the <Head> tag is
5
3734
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
6
1700
by: newlearner | last post by:
Hi, Is There any way to insert a jascript statements into a script tag which is created dynamically. i.e like ("tagName").innerHTML = string. Is there any way for the script tag. Thaks in advance for your reply.
1
2461
by: andyr | last post by:
I would like to dynamically insert a javascript call with with data retrived from the database. All I am trying to do is dynamically inserting the following <script type="text/javascript">alert(retrieved_database_id);</scriptto a panel using the ajaxToolkit:DynamicPopulateExtender Can someone enlighting me where I am going wrong or the best way to go about what I am trying to achieve.
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.