Insert Javascript

  • Thread starter Thread starter MDB
  • Start date Start date
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
 
Just have it in your ascx file.
Like
<B>MYUSERCONTROL<B>
<script>
...my javascript here.....
</scrip>

George
 
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
 
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
 
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.
 
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.
 
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>
 
Back
Top