Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to insert JavaScript code dynamically...

Reply
Thread Tools

how to insert JavaScript code dynamically...

 
 
=?Utf-8?B?SmFpbWUgU3R1YXJkbw==?=
Guest
Posts: n/a
 
      09-12-2005
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFzb24gTCBMaW5k?=
Guest
Posts: n/a
 
      09-12-2005
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

 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-12-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      09-12-2005
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

 
Reply With Quote
 
=?Utf-8?B?SmFpbWUgU3R1YXJkbw==?=
Guest
Posts: n/a
 
      09-12-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Multiple Records Using One Insert Statemen with MySQLdb module anton.ranieri.it@gmail.com Python 1 12-06-2008 12:47 PM
insert in std::map does not insert the object simon.elbaz@free.fr C++ 1 11-04-2007 11:42 PM
Insert & Insert/Repeat buttons in a detailsview eagle ASP .Net Datagrid Control 0 07-12-2007 12:47 PM
Detailsview loses insert mode contents when Insert fails... cannontrodder ASP .Net 1 07-25-2006 08:38 AM
How To Insert Code With Javascript, How to insert into a div an amountof code Sergio del Amo Javascript 4 05-29-2005 02:45 AM



Advertisments