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
George Ter-Saakov - 27 Dec 2007 17:24 GMT
Just have it in your ascx file.
Like
<B>MYUSERCONTROL<B>
<script>
...my javascript here.....
</scrip>
George
> 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
[quoted text clipped - 4 lines]
>
> TIA
MDB - 27 Dec 2007 18:35 GMT
I can't the script is created dynamically.
> Just have it in your ascx file.
> Like
[quoted text clipped - 13 lines]
>>
>> TIA
George Ter-Saakov - 27 Dec 2007 19:15 GMT
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.
>I can't the script is created dynamically.
>
[quoted text clipped - 16 lines]
>>>
>>> TIA
MDB - 27 Dec 2007 21:38 GMT
Okay, I understand now. Thanks
> It's still end up being a string? After you dynamicly created it. Right?
> Just put it into member variable _sMyScript and then
[quoted text clipped - 26 lines]
>>>>
>>>> TIA
Mark Rae [MVP] - 27 Dec 2007 21:50 GMT
> <script>
Make sure you use <script type="text/javascript"> so that your page
validates properly...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Scott M. - 27 Dec 2007 18:56 GMT
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
> 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
[quoted text clipped - 4 lines]
>
> TIA
Mark Rae [MVP] - 27 Dec 2007 21:48 GMT
> 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>

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net