ASP.NET中ImageButton圖片按鈕控件的使用

字號:


    ImageButton 說白了,就是一個能顯示圖片的按鈕,用法和Button基本一致,無非就是點擊之后觸發(fā)事件,只是比Button展現(xiàn)更豐富一些。
    一、常見 ImageButton 屬性
    
屬性 描述
ImageUrl 在 ImageButton 控件中顯示的圖像的路徑。
ToolTip 提示的文本。
AlternateText 圖像無法顯示時顯示的文本。

    二、ImageButton實例演示
    前臺代碼 ImageButton.aspx
    代碼如下:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageButton.aspx.cs" Inherits="WebControls_ImageButton" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ImageButton ID="ibtn" runat="server" Height="20px" ImageUrl="http://images.cnblogs.com/cnblogs_com/ylbtech/403178/o_sanyecao.jpg" 
                ToolTip="前臺指向" Width="118px" />
            <br />
            <br />
            <asp:ImageButton ID="ibtn2" runat="server" Height="20px" ImageUrl="http://images.cnblogs.com/cnblogs_com/ylbtech/403178/o_sanyecao.jpg"
                ToolTip="后臺指向" Width="118px" onclick="ibtn2_Click" />
        </div>
        </form>
    </body>
    </html>
    后臺代碼 ImageButton.aspx.cs
    代碼如下:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public partial class WebControls_ImageButton : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void ibtn2_Click(object sender, ImageClickEventArgs e)
        {
            //方法內(nèi)可以做很多操作
            //注冊,注冊成功,跳轉(zhuǎn)到主頁
            Response.Redirect("~/DemoHTML.aspx");
        }
    }