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.
ImageURL
DisableImageURL
MouseOverImageURL
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
{
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)
{
if (!Page.IsPostBack)
{
changedefault();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
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
}
}