<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="L_PaperSet.aspx.cs" Inherits="Lib_Web.WebForm2" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> <style type="text/css"> .style7 { width: 100%; } .style8 { width: 228px; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <table class="style7"> <tr> <td class="style8"> </td> <td> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick"> </asp:Timer> <asp:Image ID="Image1" runat="server" /> </ContentTemplate> </asp:UpdatePanel> </td> </tr> <tr> <td class="style8"> </td> <td> </td> </tr> </table> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Lib_Web { public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { NewMethod(); } } protected void Timer1_Tick(object sender, EventArgs e) { NewMethod(); } private void NewMethod() { Random rand = new Random(); int i = rand.Next(1, 4); Image1.ImageUrl = "~/L_pics/" + i.ToString() + ".jpg"; } } }