Click here to Skip to main content
Licence 
First Posted 21 Mar 2003
Views 120,401
Bookmarked 44 times

ImageButton Control in ASP.NET

By | 21 Mar 2003 | Article
Assigning disabled image to ImageButton Control

Sample Image - imageButtons.gif

Introduction

As you know, in the ASP.NET ImageButton can not be displayed as disabled. I have written the below code in order to solve this problem.

With this control you can easily show a disabled ImageButton. You can assign four different values for imageURL in this control.

  1. ImageURL
  2. DisableImageURL
  3. MouseOverImageURL
  4. MouseOutImageURL

The code

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ImageButtonTest
{
    /// <SUMMARY>
    /// Summary description for WebForm1.
    /// </SUMMARY>

    public class WebForm1 : System.Web.UI.Page
    {

        protected msWebControlsLibrary.ExImageButton btnSave;
        protected msWebControlsLibrary.ExImageButton btnCancel;
        protected msWebControlsLibrary.ExImageButton btnNew;
        protected msWebControlsLibrary.ExImageButton btnDelete;
        protected msWebControlsLibrary.ExImageButton btnSearch;
        protected System.Web.UI.HtmlControls.HtmlGenericControl divMain;
        protected System.Web.UI.WebControls.TextBox kontrol;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here

            if (!Page.IsPostBack)
            {
                changedefault();
            }
        }

        #region Web Form Designer generated code

        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET 
            // Web Form Designer.
            //

            InitializeComponent();
            base.OnInit(e);
        }

        /// <SUMMARY>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </SUMMARY>

        private void InitializeComponent()
        {    
            this.btnSave.Click += new 
                    System.EventHandler(this.btnSave_Click);
            this.btnCancel.Click += new 
                    System.EventHandler(this.btnCancel_Click);
            this.btnNew.Click += new 
                    System.EventHandler(this.btnNew_Click);
            this.btnDelete.Click += new 
                    System.EventHandler(this.btnDelete_Click);
            this.btnSearch.Click += new 
                    System.EventHandler(this.btnSearch_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion

        #region ToolBarButton Events

        private void changeallfalse()
        {
            btnSave.Enabled      = false;
            btnDelete.Enabled = false;
            btnNew.Enabled = false;
            btnCancel.Enabled = false;
            btnSearch.Enabled = false;  
        }

        private void changeupdate()
        {
            if (kontrol.Text!="0" )
            {
                btnSave.Enabled = true;
                btnDelete.Enabled = true;
                btnNew.Enabled = true;
                btnCancel.Enabled = true;
                btnSearch.Enabled = true;

                kontrol.Text = "2";
            }

        }

        private void changenew()
        {

            btnSave.Enabled      = true;
            btnDelete.Enabled = false;
            btnNew.Enabled = false;
            btnCancel.Enabled = true;
            btnSearch.Enabled = false;

            kontrol.Text = "1";
        }
          
        private void changenavigate()
        {
            btnSave.Enabled      = false;
            btnDelete.Enabled = false;
            btnNew.Enabled = true;
            btnCancel.Enabled = true;
            btnSearch.Enabled = true;
        }

        private void changedefault()
        {
            btnSave.Enabled      = false;
            btnDelete.Enabled = false;
            btnNew.Enabled = true;
            btnCancel.Enabled = true;

            kontrol.Text = "0";
            btnSearch.Enabled = true;

        }

        #endregion

        #region ToolBarButton ClickEvents

        private void btnSave_Click(object sender, System.EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            changedefault();
        }

        private void btnNew_Click(object sender, System.EventArgs e)
        {
            changenew();
        }

        private void btnDelete_Click(object sender, System.EventArgs e)
        {

        }

        private void btnSearch_Click(object sender, System.EventArgs e)
        {
            if (kontrol.Text=="2") { changedefault();return; }
            kontrol.Text = "0";

            btnCancel .Enabled = false;
            btnSave.Enabled      = false;

        }

        #endregion
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

mikas

Web Developer

Turkey Turkey

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNice article, thanks! PinmemberMenthol21:45 3 Jul '08  
QuestionWhy a composite control? PinmemberRobert Cheek12:23 3 Apr '06  
GeneralA little re-touch PinsussFernando Benavides7:08 17 Nov '04  
GeneralRe: A little re-touch Pinmemberlegcsabi12:10 26 May '08  
GeneralExImageButton and Netscape Pinmemberpatur5511:36 7 Jun '04  
GeneralNeed help!! PinsussAnonymous10:44 1 Apr '03  
GeneralRe: Need help!! PinsussAnonymous19:19 1 Apr '03  
GeneralHi--..... PinsussAnonymous8:24 29 Mar '03  
GeneralGreat button image Pinmemberbenben1:23 24 Mar '03  
GeneralRe: Great button image PinsussAnonymous5:47 24 Mar '03  
GeneralNice introduction! PinmemberJörgen Sigvardsson5:52 22 Mar '03  
GeneralRe: Nice introduction! PinmemberMarc Clifton12:25 22 Mar '03  
GeneralRe: Nice introduction! PinmemberJörgen Sigvardsson13:26 22 Mar '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 22 Mar 2003
Article Copyright 2003 by mikas
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid