You don't have closing </script> tag for including jquery.
Anthon, I thought that by ending the tab with /> would sufice. So I implementd your recommendation and it almost worked. For some reson the script rotates after the page load but goes directly to the last slide. I have a total of 17 images, first is loaded
in the image tag and after the 10 sec. interval the last image is displayed. So this not neccessarily related to the initial issue, but I'm throwing it out anyway.
One option is to use javascript rotating an image at client side
BU XI, I need to be able to access the directory where the images are located. This is a prototype app and once I'll have it working, code will be copied to a SharePoint Content Editor web part.
hiren.sharma
Participant
1460 Points
311 Posts
Re: Javascript won't run in code file
Jun 27, 2011 06:06 AM|LINK
Try the following Steps and it should work
1. <script src='Scripts/jquery-1.3.2.min.js' type='text/javascript' ></script> <=== Seperate the Script Tag
2. Keep the whole code under document.ready()
3. Use RegisterStartupScript instead of RegisterClientScriptBlock and set the fourth argument as false as you are enclosing the <script> tag your self
IT SHOULD WORK NOW
HOPE IT HELPS
HAPPY CODING
Try out My Blog | Visit My Website
asteranup
All-Star
30184 Points
4906 Posts
Re: Javascript won't run in code file
Jun 27, 2011 07:54 AM|LINK
Hi,
Try this-
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script> <script type="text/javascript"> var i = 0; function Rotate() { i++; if (i == images.length) i = 0; $("#imgSlebb").attr("src", images[i]); $("#imgSlebb").attr("width", "130"); $("#imgSlebb").attr("height", "130"); } $(function() { setInterval('Rotate()', 1000); $("#imgSlebb").attr("src", images[0]); }); </script> </head> <body> <form id="form1" runat="server"> <div> <img id="imgSlebb" /> </div> </form> </body> </html>protected void Page_Load(object sender, EventArgs e) { var images = new string[]{ "http://www.gallery2c.com/admin/Upload/ThumbNail/moda01.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda02.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda03.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda04.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda05.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda06.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda07.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda08.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda09.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda10.jpg", "http://www.gallery2c.com/admin/Upload/ThumbNail/moda11.jpg"}; System.Web.Script.Serialization.JavaScriptSerializer s= new System.Web.Script.Serialization.JavaScriptSerializer(); string imageString = s.Serialize(images); imageString = imageString.Replace("[", "").Replace("]", ""); ClientScript.RegisterArrayDeclaration("images", imageString);Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
EJM
Member
190 Points
415 Posts
Re: Javascript won't run in code file
Jun 27, 2011 07:47 PM|LINK
Anthon, I thought that by ending the tab with /> would sufice. So I implementd your recommendation and it almost worked. For some reson the script rotates after the page load but goes directly to the last slide. I have a total of 17 images, first is loaded in the image tag and after the 10 sec. interval the last image is displayed. So this not neccessarily related to the initial issue, but I'm throwing it out anyway.
Thanks for your time.
EJM
Member
190 Points
415 Posts
Re: Javascript won't run in code file
Jun 27, 2011 07:52 PM|LINK
BU XI, I need to be able to access the directory where the images are located. This is a prototype app and once I'll have it working, code will be copied to a SharePoint Content Editor web part.
Thanks for your time!
Anton Palyok
Contributor
2526 Points
404 Posts
Re: Javascript won't run in code file
Jun 29, 2011 10:30 AM|LINK
You should just to remember that <script> tag must have own closing tag.
this is because you have mistake in your code:
csScript.Append(@"$('#imgSlebb').attr('src','images/Slide" + iCounter + ".jpg');");This code always shows last picture.
You can fix it like this:
csScript.Append(@"$('#imgSlebb').attr('src','images/Slide' + i + '.jpg');");EJM
Member
190 Points
415 Posts
Re: Javascript won't run in code file
Jun 29, 2011 03:08 PM|LINK
Anton, Thanks for your time. It' all works.
Also thanks to all who contributed!!!
Have great day.