Insert Javascript

M

MDB

Hello all, I have a web user control that displays a single image from
javascript. In order to insert the javascript into the webcontrol, I use
the page.registrer script call in the code behind since the images are
dynamically created. This works however, I can not figure out how to get it
to insert the script where the user control is located rather than the top
of the page. Can someone please point me into the right direction?

TIA
 
G

George Ter-Saakov

Just have it in your ascx file.
Like
<B>MYUSERCONTROL<B>
<script>
...my javascript here.....
</scrip>

George
 
M

MDB

I can't the script is created dynamically.


George Ter-Saakov said:
Just have it in your ascx file.
Like
<B>MYUSERCONTROL<B>
<script>
...my javascript here.....
</scrip>

George
 
S

Scott M.

Your scripts can be placed either at the top of the page or the bottom using
new ASP.NET 2.0 methods:

page.ClientScript.RegisterStartupScript (bottom of page)
page.ClientScript.RegisterClientScriptBlock (top of page)

-Scott
 
G

George Ter-Saakov

It's still end up being a string? After you dynamicly created it. Right?
Just put it into member variable _sMyScript and then
Have it like that
<B>MYUSERCONTROL<B>
<script>
<%=_sMyScript%>
</script>

George.
 
M

MDB

Okay, I understand now. Thanks

George Ter-Saakov said:
It's still end up being a string? After you dynamicly created it. Right?
Just put it into member variable _sMyScript and then
Have it like that
<B>MYUSERCONTROL<B>
<script>
<%=_sMyScript%>
</script>

George.
 
M

Mark Rae [MVP]

Your scripts can be placed either at the top of the page or the bottom
using new ASP.NET 2.0 methods:

page.ClientScript.RegisterStartupScript (bottom of page)
page.ClientScript.RegisterClientScriptBlock (top of page)

To be slightly more precise, RegisterClientScriptBlock inserts the
JavaScript block just underneath the <form runat="server"> tag which means
that it doesn't have access to any of the form elements because they haven't
been created yet, whereas RegisterStartupScript inserts the JavaScript block
just above the <form runat="server"> tag's closing </form> tag, e.g.

<form id="aspnetForm" runat="server">
<script type="text/javascript">
// this was created with RegisterClientScriptBlock
</script>

<!-- other form elements -->

<script type="text/javascript">
// this was created with RegisterStartupScript
</script>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top