ASP.NET Tutorial/ASP.net Controls/ImageButton — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:30, 26 мая 2010
Important properties, methods and events of ImageButton control
<source lang="csharp">
AccessKey: a key that navigates to the ImageButton control. AlternateText: alternate text for the image (required for accessibility). DescriptionUrl: a link to a page that contains a detailed description of the image (required to make a complex image accessible). CommandArgument: a command argument that is passed to the Command event. CommandName: command name that is passed to the Command event. Enabled: disable the ImageButton control. GenerateEmptyAlternateText: set the AlternateText property to an empty string. ImageAlign: align the image relative to other HTML elements in the page.
Possible values are AbsBottom, AbsMiddle, Baseline, Bottom, Left, Middle, NotSet, Right, TextTop, and Top.
ImageUrl: URL to the image. OnClientClick: a client-side script that executes when the ImageButton is clicked. PostBackUrl: post a form to a particular page. TabIndex: tab order of the ImageButton control. Focus: set the initial form focus to the ImageButton control. Click: Raised when the ImageButton control is clicked. Command: Raised when the ImageButton control is clicked.
The CommandName and CommandArgument are passed to this event.</source>
The second parameter passed in is an instance of the ImageClickEventArgs class.
<source lang="csharp">
This class has the following properties: X: The x coordinate relative to the image the user clicked. Y: The y coordinate relative to the image the user clicked.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">
protected void btnTarget_Click(object sender, ImageClickEventArgs e) { if ((e.X > 90 && e.X < 110) && (e.Y > 90 && e.Y < 110)) lblResult.Text = "You hit the target!"; else lblResult.Text = "You missed!"; }
</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">
<title>ImageButton Target</title>
</head> <body>
<form id="form1" runat="server">
<asp:ImageButton id="btnTarget" ImageUrl="http://www.nfex.ru/style/logo.png" Runat="server" OnClick="btnTarget_Click" />
<asp:Label id="lblResult" Runat="server" />
</form>
</body> </html></source>
Using the ImageButton Control
<source lang="csharp">
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">
protected void btnSubmit_Click(object sender, ImageClickEventArgs e) { lblResults.Text = "First Name: " + txtFirstName.Text; lblResults.Text += "
Last Name: " + txtLastName.Text; }
</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">
<title>Show ImageButton</title>
</head> <body>
<form id="form1" runat="server">
<asp:Label id="lblFirstName" Text="First Name:" AssociatedControlID="txtFirstName" Runat="server" />
<asp:TextBox id="txtFirstName" Runat="server" />
<asp:Label id="lblLastName" Text="Last Name:" AssociatedControlID="txtLastName" Runat="server" />
<asp:TextBox id="txtLastName" Runat="server" />
<asp:ImageButton id="btnSubmit" ImageUrl="http://www.nfex.ru/style/logo.png" AlternateText="Submit Form" Runat="server" OnClick="btnSubmit_Click" />
<asp:Label id="lblResults" Runat="server" />
</form>
</body> </html></source>