Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Insert Javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MDB - 27 Dec 2007 15:45 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.