You must Sign In to post a response.
  • Category: JavaScript

    Image slider in asp.net

    hi friends,

    can anyone me with the code for image slider.i am having all my images in a folder so i need to get images from folder.

    protected void Timer1_Tick(object sender, EventArgs e)
    {
    SetImageUrl();

    }
    private void SetImageUrl()
    {

    Random _rand = new Random();
    int i = _rand.Next(1, 3);
    Image1.ImageUrl = "~/Images/" + i.ToString() + ".jpg";
    }
    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
    </asp:Timer>

    <asp:Image Style="width: 1000px; height: 500px;" ID="Image1" runat="server" />

    i am using this to get the images but its not working properly.
    i need a your help with coding.
  • #763737
    You can use javascript or JQuery to use image slider concept
    you can use following code
    var imgArray = []
    imgArray[0] = "url('../danallenfilms/images/screenshots/husky/shot1.png')";
    imgArray[1] = "url('../danallenfilms/images/screenshots/husky/shot2.png')";
    imgArray[2] = "url('../danallenfilms/images/screenshots/husky/shot3.png')";
    imgArray[3] = "url('../danallenfilms/images/screenshots/husky/shot4.png')";
    imgArray[4] = "url('../danallenfilms/images/screenshots/husky/shot5.png')";

    var numOfImg = imgArray.length,
    elem = document.getElementById('imgDisplay');

    setInterval(function () {
    var randomNum = Math.floor(Math.random()*(numOfImg));
    elem.style.backgroundImage = imgArray[randomNum];
    }, 1000);
    or
    checkout following link
    http://www.codeproject.com/Tips/670085/Image-Sliding-Effect-with-JavaScript
    http://codepen.io/zuraizm/pen/vGDHl

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763771
    Declare the following outside the function SetImageUrl()

    var i = 0;

    And increment the value of "i" inside of SetImageUrl()

    By Nathan
    Direction is important than speed


  • Sign In to post your comments