Sunday, June 1, 2014

Button, LinkButton, ImageButton

The Button, LinkButton, ImageButton are used to post a page to the server.
   Button:- The Button control is used to display a push button.
   LinkButton:- LinkButton displays the button like a Hyperlink.
   ImageButton:- ImageButton provides the flexibility of associating an image with the button using ImageUrl property.

Example :-
WebForm1.aspx :-
 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_14_link_imagebutton.WebForm1" %>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">  
 <html xmlns="">  
 <head runat="server">  
   <form id="form1" runat="server">  
     <asp:Button ID="Button1" runat="server" onclick="Button1_Click"   
       onclientclick="alert(&quot;You are about to submit the page&quot;)"   
       Text="Submit" />  
     <br />  
     <br />  
     <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click"   
       onclientclick="return confirm(&quot;Are you sure u want to delete&quot;)">Submit</asp:LinkButton>  
     <br />  
     <br />  
     <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Image/1452.jpg"   
       onclientclick="alert(&quot;your are about to submit the page&quot;)"   
       Width="43px" />  

WebForm1.aspx.cs :-
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 namespace _14_link_imagebutton  
   public partial class WebForm1 : System.Web.UI.Page  
     protected void Button1_Click(object sender, EventArgs e)  
       Response.Write("submit button is clicked");  
     protected void LinkButton1_Click(object sender, EventArgs e)  
       Response.Write("link button is clicked");  
     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)  
       Response.Write("image button is clicked");  

Onclientclick is used to associate some javascript that we want to run in response to the click event on the client.

No comments:

Post a Comment