Introduction : ImageButton Control is similar to Button Control. Everything is similar in properties and events, but User can see Image instead of Button.ImageButton Control is similar to Button Control. Everything is similar in properties and events, but User can see Image instead of Button.
Important Properties of Asp.NET Webserver ImageButton control are given below. You can Set /Get these properties at Design time or at Runtime.
CausesValidation - Accept Boolean Value - Used to Validate the page when Image Button click event fires.
Enabled - Accept Boolean Value- Used to Get/Set Imagebutton Enabled.
Height - Accept IntegerValue - Used to Set/Get height of the Image.
OnClientClick - Accept String value - Used specify the client side function name (eg. Javascript function name.This property is available in .NET Framework 2.0 onwards which will execute the client side function by just setting the function name.)
Width - Accept IntergerValue - Used to set the width of the ImageButton
Events available in Asp.Net Webserver ImageButton Control are:
Click - If PostbackURL property is set then click event will not fire on clicking of the Image, it will go to Target page. Init Load PreRender UnLoad
Lets See an example
Your .aspx code will look like this for a WebServer Control ImageButton <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/dotnetsparklogo.gif" onclientclick="MyJavaScriptFunction()" PostBackUrl="~/Default2.aspx" />
Full Html Code Used in this example <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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>ImageButton Samples - DotNetSpark.com</title> <script language="javascript" type="text/javascript"> function MyJavaScriptFunction() { alert("Hello"); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/dotnetsparklogo.gif" onclientclick="MyJavaScriptFunction()" PostBackUrl="~/Default2.aspx" /> </div> </form> </body> </html>
|