The Use of ImageButton Picture Button Control in ASP. NET

  • 2021-07-21 08:12:51
  • OfStack

To put it bluntly, ImageButton is a button that can display pictures. Its usage is basically the same as that of Button. It is nothing more than triggering events after clicking, but it is richer than Button.

1. Common ImageButton attributes

属性 描述
ImageUrl 在 ImageButton 控件中显示的图像的路径。
ToolTip 提示的文本。
AlternateText 图像无法显示时显示的文本。

2. ImageButton example demonstration

Foreground code 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=" Foreground pointing " 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=" Background pointing " Width="118px" onclick="ibtn2_Click" />
    </div>
    </form>
</body>
</html>

Background code 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)
    {
        // You can do a lot of things inside the method
        // Register, register successfully, jump to home page
        Response.Redirect("~/DemoHTML.aspx");
    }
}


Related articles: