Programming Microsoft ASP.NET 4 - Dino Esposito [138]
Name
Description
CausesValidation
Boolean value, indicates whether validation is performed when the control is clicked.
CommandArgument
Gets or sets an optional parameter passed to the button’s Command event along with the associated CommandName.
CommandName
Gets or sets the command name associated with the button that is passed to the Command event.
PostBackUrl
Indicates the URL that will handle the postback triggered through the button control. This feature is known as cross-page postback.
Text
Gets or sets the caption of the button.
ValidationGroup
Gets or sets the name of the validation group that the button belongs to.
In addition to the properties defined by the IButtonControl interface, the Button class features two properties for handling the steps following the user’s clicking. The properties are OnClientClick and UseSubmitBehavior. The former lets you define the name of the JavaScript function to run when the client-side onclick event is fired. The following two statements are perfectly legal and equivalent:
Button1.OnClientClick = "ShowMessage()";
Button1.Attributes["onclick"] = "ShowMessage()";
The OnClientClick property is also available on LinkButton and ImageButton controls.
By default, the Button class is rendered through an tag. In this way, it takes advantage of the browser’s submit mechanism to post back. The UseSubmitBehavior property allows you to change the default behavior. Set the UseSubmitBehavior property to false and the control will render out through an tag. Also in this case, though, the Button control remains a postback button. When UseSubmitBehavior is false, the control’s onclick client event handler is bound to a piece of JavaScript code (the __doPostBack function) that provides the ASP.NET postback mechanism just like for LinkButton or ImageButton controls.
Important
Buttons are not the only controls that can trigger a postback. Text boxes and check boxes (plus a few more data-bound list controls, which you’ll see in Chapter 10) also can start a postback if their AutoPostBack property is set to true. (Note that the default setting is false.) When this happens, the control wires up to a client-side event—onchange for text boxes, and onclick for check boxes—and initiates a postback operation via script. In light of this, virtually any control can be modified to post back.
HyperLinks
The HyperLink control creates a link to another Web page and is typically displayed through the text stored in the Text property. Alternatively, the hyperlink can be displayed as an image; in this case, the URL of the image is stored in the ImageUrl property. Note that if both the Text and ImageUrl properties are set, the ImageUrl property takes precedence. In this case, the content of the Text property is displayed as a ToolTip when the mouse hovers over the control’s area.
The NavigateUrl property indicates the URL the hyperlink is pointing to. The Target property is the name of the window or frame that will contain the output of the target URL.
Images and Image Buttons
The Image control displays an image on the Web page. The path to the image is set through the ImageUrl property. Image URLs can be either relative or absolute, with most programmers showing a clear preference for relative URLs because they make a Web site inherently easier to move. You can also specify alternate text to display when the image is not available or when the browser doesn’t render the image for some reason. The property to use in this case is AlternateText. The image alignment with respect to other elements on the page is set by using the ImageAlign property. Feasible values are taken from the homonymous enum type (for example: ImageAlign.Left, ImageAlign.Middle, and so forth).
The Image control is not a clickable component and is simply limited to displaying an image. If you need to capture mouse clicks on the image, use the ImageButton control instead. The ImageButton class descends from Image and extends it with a couple of