The AsyncImage is an Async-Enabled image server control, and it's one of four AsyncWebControls that give you the ability to sort.
<%@ Register Assembly="AsyncControls" Namespace="DelvingWare.AsyncControls" TagPrefix="dw" %> <dw:AsyncButton runat="server" ID="btVisible" CssClass="greyButton" Text="Hide AsyncImage" OnClick="btVisible_Click" /> <p/> <dw:AsyncImage runat="server" ID="imgMain" ImageUrl="../images/imageIcon.gif" OnClick="imgMain_Click" OnMouseOut="imgMain_MouseOut" OnMouseOver="imgMain_MouseOver" /> <dw:AsyncButton runat="server" ID="btMain" CssClass="greyButton" Text="Show Random Image" OnClick="btMain_Click" /> <dw:AsyncLabel runat="server" ID="lblMain" RenderMode="bold" />
using System; using DelvingWare.AsyncControls; ... string [] imgUrls = { "../images/TabPanelIcon.gif", "../images/SlidePanelIcon.gif", "../images/PageRepeaterIcon.gif" }; protected void imgMain_MouseOut( object sender, AsyncEventArgs ae ) { // update the AsyncLabel lblMain.Text = "Mouse out."; } protected void imgMain_MouseOver( object sender, AsyncEventArgs ae ) { // update the AsyncLabel lblMain.Text = "Mouse over."; } protected void imgMain_Click( object sender, AsyncEventArgs ae ) { // update the AsyncLabel lblMain.Text = "Image clicked."; } protected void btMain_Click( object sender, AsyncEventArgs ae ) { // get a random index int index = new Random().Next(imgUrls.Length); // update the image source url imgMain.ImageUrl = imgUrls[index]; } protected void btVisible_Click( object sender, AsyncEventArgs ae ) { // update the AsyncButton if ( imgMain.Visible ) btVisible.Text = "Show AsyncImage"; else btVisible.Text = "Hide AsyncImage"; // toggle visibility imgMain.Visible = !imgMain.Visible; }
Imports System Imports DelvingWare.AsyncControls ...Dim imgUrls() As String Protected Sub imgMain_MouseOut(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' update the AsyncLabel lblMain.Text = "Mouse out." End Sub Protected Sub imgMain_MouseOver(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' update the AsyncLabel lblMain.Text = "Mouse over." End Sub Protected Sub imgMain_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' update the AsyncLabel lblMain.Text = "Image clicked." End Sub Protected Sub btMain_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' get a random index Dim index As Integer = (New Random + Next(imgUrls.Length)) ' update the image source url imgMain.ImageUrl = imgUrls(index) End Sub Protected Sub btVisible_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' update the AsyncButton If imgMain.Visible Then btVisible.Text = "Show AsyncImage" Else btVisible.Text = "Hide AsyncImage" End If ' toggle visibility imgMain.Visible = Not imgMain.Visible End Sub