欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET中ImageButton图片按钮控件的使用

程序员文章站 2024-02-12 14:30:46
imagebutton 说白了,就是一个能显示图片的按钮,用法和button基本一致,无非就是点击之后触发事件,只是比button展现更丰富一些。 一、常见 imageb...

imagebutton 说白了,就是一个能显示图片的按钮,用法和button基本一致,无非就是点击之后触发事件,只是比button展现更丰富一些。

一、常见 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)
    {
        //方法内可以做很多操作
        //注册,注册成功,跳转到主页
        response.redirect("~/demohtml.aspx");
    }
}
相关标签: ASP.NET ImageButton