Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging pictures in a website gallery form
    primarykey
    data
    text
    <p>I have tried for about a week now and cannot solve my problem. What I want to do is have a web page that will basicaly scroll through 5 or 6 pictures by <code>clicking a next or prev asp:button</code>. Can someone help me from scratch how to achieve this.</p> <p>I am using visual studio web developer and have a blank web site made with a master page. I want to add this gallary function to the auto generated <code>Default.apsx</code> file.</p> <p>My picture name are <code>pic001.jpg; pic002.jpg; pic003.jpg</code> and so forth</p> <p>all I want is a button on the left saying previous which will take you to the previous image, a button on the right that says next which will show you the next picture and in the middle is a picture (the one that changes)</p> <p>Please help with this problem I have tried and failed rather horribly at it, Many thanks to the one who can help</p> <p>This is some code of my attempts:</p> <h2>Default.aspx file</h2> <pre><code>&lt;%@ Page Title="Default" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server" &gt; &lt;script src="myJava.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server" &gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt; GALLARY &lt;/td&gt;&lt;/tr&gt; &lt;!--Header--&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:Button ID="Button1" runat="server" Text="Prev" OnClientClick="getPrevImage()"/&gt; &lt;/td&gt; &lt;td&gt; &lt;img ID="pic" alt="" src="" runat="server" width="400" height="400" /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Button ID="Button2" runat="server" Text="Next" OnClientClick="getNextImage()"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/asp:Content&gt; </code></pre> <h2>Default.aspx.cs file</h2> <pre><code>public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string script = string.Empty; script += "&lt;script language='javascript'&gt;"; script += "init()"; script += "&lt;/script&gt;"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", script); } } } </code></pre> <h2>myJava.js file</h2> <pre><code>var imagePath = new Array(); var imageIndex = 0; function init(){ addPath("pic001.jpg"); addPath("pic002.jpg"); addPath("pic003.jpg"); addPath("pic004.jpg"); addPath("pic005.jpg"); getImagePath(0); } function addPath(path){ var index = imagePath.length; imagePath[index++] = path; } function getImagePath(index){ var length = imagePath.length; if(index &lt;= length){ if(index &gt;= 0){ document.getElementById("MainContent_pic").src = imagePath[index]; document.getElementById("MainContent_pic").alt = imagePath[index]; imageIndex = index; } } else { document.getElementById("MainContent_pic").src = "DOES NOT EXIST"; document.getElementById("MainContent_pic").alt = "DOES NOT EXIST"; } } function getNextImage(){ var length = imagePath.length; var index = imageIndex; if(index++ &lt; length--){ if(imagePath[index] != null){ imageIndex = index; document.getElementById("MainContent_pic").src = imagePath[index]; document.getElementById("MainContent_pic").alt = imagePath[index]; } } } function getPrevImage(){ var index = imageIndex; if(index-- &gt;= 0){ if(imagePath[index] != null){ imageIndex = index; document.getElementById("MainContent_pic").src = imagePath[index]; document.getElementById("MainContent_pic").alt = imagePath[index]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload