Freigeben über


HtmlInputImage Server Control Declarative Syntax

Creates a server-side control that maps to the <input type=image> HTML element and allows you to create a button that displays an image.

<input
    Type="Image"
    EnableViewState="False|True"
    Id="string"
    Visible="False|True"
    OnDataBinding="OnDataBinding event handler"
    OnDisposed="OnDisposed event handler"
    OnInit="OnInit event handler"
    OnLoad="OnLoad event handler"
    OnPreRender="OnPreRender event handler"
    OnServerClick="OnServerClick event handler"
    OnUnload="OnUnload event handler"
    runat="server"
    />

Remarks

Use the HtmlInputImage control to program against the HTML <input type=image> element. You can use this control in conjunction with the HtmlInputText, HtmlTextArea, and other controls to construct user input forms. Because this control is the <input type=image> element that is run on the server, it offers the same button customization as HTML. This control offers an alternative for browsers that do not support dynamic HTML (DHTML) and the HtmlButton control.

Note

This control does not require a closing tag.

One of the advantages of HTML controls over Web controls is that server-side events do not conflict with events that occur on the client, unless the server and client code themselves countermand each other. If this is the case, you can use DHTML events to modify the appearance of any image that you include on your Web Forms page.

Example

The following example compares a static image button control with an image button control that uses the DHTML onMouseOver event (which displays the image of a banana) and the onMouseOut event (which displays the original mango image). Both image buttons include an OnServerClick event handler.

<%@ Page Language="VB" AutoEventWireup="True" %>
<!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>
<title>HtmlInputImage Control</title>

   <script runat="server">
      Sub Button1_Click(Source As Object, e As ImageClickEventArgs)
         Span1.InnerHtml = "You clicked button1"
      End Sub

      Sub Button2_Click(Source As Object, e As ImageClickEventArgs)
         Span1.InnerHtml = "You clicked button2"
      End Sub
   </script>

</head>
<body>
    <h3>HtmlInputImage Sample</h3>
    <form id="Form1" runat="server">
        <input type="image" 
               id="InputImage1" 
               src="/images/mango.jpg" 
               onserverclick="Button1_Click" 
               runat="server" />
        <br />
        <input type="image" 
               id="InputImage2" 
               src="/images/mango.jpg"
               onmouseover="this.src='/images/banana.jpg';"
               onmouseout="this.src='/images/mango.jpg';"
               onserverclick="Button2_Click"
               runat="server" />
        &nbsp;With rollover effect (HTML 4.0)
        <br />
        <span id="Span1" runat="server" />
    </form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>
<title>HtmlInputImage Control</title>

   <script runat="server">
      void Button1_Click(object Source, ImageClickEventArgs e) 
      {
         Span1.InnerHtml="You clicked button1";
      }
      void Button2_Click(object Source, ImageClickEventArgs e) 
      {
         Span1.InnerHtml="You clicked button2";
      }
   </script>

</head>
<body>
    <h3>HtmlInputImage Sample</h3>
    <form id="Form1" runat="server">
        <input type="image" 
               id="InputImage1" 
               src="/images/mango.jpg" 
               onserverclick="Button1_Click" 
               runat="server" />
        <br />
        <input type="image" 
               id="InputImage2" 
               src="/images/mango.jpg"
               onmouseover="this.src='/images/banana.jpg';"
               onmouseout="this.src='/images/mango.jpg';"
               onserverclick="Button2_Click"
               runat="server" />
        &nbsp;With rollover effect (HTML 4.0)
        <br />
        <span id="Span1" runat="server" />
    </form>
</body>
</html>

See Also

Reference

HtmlInputImage

Other Resources

HTML Server Controls