473,387 Members | 1,925 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,387 software developers and data experts.

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.RegisterStartupScript(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 2202
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.litJavaScript.Text = "<script
type=\"text/javascript\">Javascript</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.RegisterStartupScript(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.RegisterClientScriptBlock 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**********@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.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.RegisterStartupScript(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.RegisterStartupScript(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 RegisterStartupScript, 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.litJavaScript.Text = "<script
type=\"text/javascript\">Javascript</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.RegisterStartupScript(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
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...
4
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...
3
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,...
4
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...
4
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...
0
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>...
5
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....
6
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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: 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,...

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.