日期:2014-05-17  浏览次数:20401 次

如何在 C#.net 开发中实现 网页的 ImageButton 点击 循环 响应不同事件?


实现要求:
1.C#.net网页开发,开发工具VS2010;



2.比如一个ImageButton,要实现点击一次显示一个内容<或是响应事件>,再点击显示另一个,再点击显示第三个内容,再点击显示第一个,如此循环..



3.在实现点击后ImageButton换成相对内容所需要的按钮图标;



求高手指点迷津!小弟不胜感激!!!!

处理提问

------解决方案--------------------
完整的例子
HTML code
<%@ Page Language="C#" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  String[] data = { "A", "B", "C" };
  String[] url = { "http://avatar.profile.csdn.net/C/9/4/2_net_lover.jpg", "http://avatar.profile.csdn.net/B/3/8/2_huaxinyuanshuai.jpg", "http://avatar.profile.csdn.net/D/E/5/2_smith_hjq.jpg" };

  protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  {
    int count = Int32.Parse(HiddenField1.Value) + 1;
    if (count >= data.Length) count = 0;
    HiddenField1.Value = count.ToString();
    Literal1.Text = data[count];
    ImageButton1.ImageUrl = url[count];
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      Literal1.Text = data[0];
      ImageButton1.ImageUrl = url[0];
    }
  }
</script>
<html>
<head>
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:Literal ID="Literal1" runat="server"></asp:Literal>
  <asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" />
  <asp:HiddenField ID="HiddenField1" runat="server" Value="0" />
  </form>
</body>
</html>