Sunday 29 December 2013

Images slideshow change the image every 1 second async in ASP.NET

In this article we are going to see how to change the image dynamically at every one second async like  image slideshow. For this we are using the script manager. To update the image async place the img control inside the update panel.

Place the files inside a Folder.Drag and drop the timer control inside the update panel and set the time interval 1000 milliseconds.

HTML

<form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <div style="width:200px;height:50px">
            <asp:Image Width="400px" Height="300px" ID="Image1" runat="server" />
        </div>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
            </asp:Timer>
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>



C#
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Random rand = new Random();
            Image1.ImageUrl = "~/images/" + rand.Next(1, 8) + ".jpg";
        }


Output:


From this article you can learn how to change the image dynamically and show as image slideshow.

No comments:

Post a Comment