11 Jul 2013

How to Use ImageButton Control By C# ASP.NET

Hello Geeks .. Today's Post Is A Simple Example On How To Use The Image Button Control in ASP.NET Using C# .
So Before We Dive Into Our little post , let me give You a Brief Description About This Control .
Well .. Image Button Control Is a Control That Displays An Image Instead Of Text .
You Can Find This Control Within the System.Web.UI.WebControls namespace.
You Can Use This Control To Map Images and Get Co-ordinations for example .

Some Properties Of The ImageButton :

  • PostBackUrl : Set the Url Of The Web Page to Post from the current web page when the ImageButton is Clicked 
  • CauseValidation : set a value showing whether or not validation is performed when the ImageButton control is clicked.
  • OnClientClick : Set The Client Side Script Which Is Executed When An ImageButton Control Click Event is Fired. 

Download Working Sample (Media Fire ) : ImageButton ASP.NET Sample

Steps For Implementing The Code Yourself : 

  1. Open Visual Studio 2012 And Create An Empty ASP.NET Web Application .
  2. Right Click On The Solution Explorer .. Add New Item .. Web Form .

  3. Add The HTML Code inside the webform.aspx I just gave you the link to download
  4. Go To The ImageButton Click Event and Implement This Code : 
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
               Result.Text ="X="+e.X.ToString() + ",Y=" + e.Y.ToString(); 

Related Posts : 

Best Wishes Everybody :)