Image

Этот элемент управления нужно применять тогда, когда в C# коде происходят какие либо изменения.
Скрыть

Показать

Копировать
  Default.aspx  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta charset="utf-8" />
 <title></title>
 <style>
  body {
   background-color: #FAFFFF;
  }
  .main {
   height: 550px;
   width: 376px;
   position: absolute;
   top: 50%;
   left: 50%;
   margin-top: -275px;
   margin-left: -188px;
   border: 1px solid #3BA9DE;
   border-radius: 20px;
  }
  .top {
   height: 500px;
   width: 376px;
   border-top-left-radius: 20px;
   border-top-right-radius: 20px;
  }
  #Image1 {
   border-top-left-radius: 20px;
   border-top-right-radius: 20px;
  }
  .bottom {
   height: 49px;
   width: 376px;
   border-bottom-left-radius: 20px;
   border-bottom-right-radius: 20px;
   border-top: 1px solid #3BA9DE;
   background-color:azure;
  }
  .button {
   height: 50px;
   width: 100px;
   float: left;
  }
  #ImageButtonLeft {
   border-bottom-left-radius: 20px;
  }
  #ImageButtonRight {
   border-bottom-right-radius: 20px;
  }
  .number {
   height: 50px;
   width: 174px;
   float: left;
   border-left: 1px solid #3BA9DE;
   border-right: 1px solid #3BA9DE;
   line-height: 50px;
   text-align: center;
   font-size: 30px;
  }
 </style>
</head>
<body>
 <form id="form1" runat="server">
  <div class="main">
   <div class="top">
    <asp:Image ID="Image1" runat="server" />
   </div>
   <div class="bottom">
    <div class="button">
     <asp:ImageButton ID="ImageButtonLeft" runat="server" Height="50px" ImageUrl="~/img/left.png" Width="100px" OnClick="ImageButtonLeft_Click" />
    </div>
    <div class="number">
     <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    <div class="button">
     <asp:ImageButton ID="ImageButtonRight" runat="server" Height="50px" ImageUrl="~/img/right.png" Width="100px" OnClick="ImageButtonRight_Click" />
    </div>
   </div>
  </div>
 </form>
</body>
</html>
Скрыть

Показать

Копировать
  Default.aspx.cs  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page {
 int image = 1;
 //количество изображений
 int amount = 15;
 protected void Page_Load(object sender, EventArgs e) {
  if(!IsPostBack) {
   //начальная загрузка страницы
   Image1.ImageUrl = "img/1.jpg";
   Label1.Text = "1";
  }
  else {
   //чтение значения из сессии
   image = Convert.ToInt32(Session["image"]);
   Image1.ImageUrl = "img/" + image + ".jpg";
   Label1.Text = image.ToString();
  }
 }
 //Left
 protected void ImageButtonLeft_Click(object sender, ImageClickEventArgs e) {
  //уменьшаем изображение на 1
  image--;
  //если изображений больше, чем их действительно
  if(image < 1) {
   image = 15;
  }
  Image1.ImageUrl = "img/" + image + ".jpg";
  Label1.Text = image.ToString();
  //запись значения в сессию
  Session["image"] = image.ToString();
 }
 //Right
 protected void ImageButtonRight_Click(object sender, ImageClickEventArgs e) {
  //увеличиваем изображение на 1
  image++;
  //если изображений больше, чем их действительно
  if(image > amount) {
   image = 1;
  }
  Image1.ImageUrl = "img/" + image + ".jpg";
  Label1.Text = image.ToString();
  //запись значения в сессию
  Session["image"] = image.ToString();
 }
}