在 ASP.NET 中,ImageButton控件

分享于 

5分钟阅读

Web开发

  繁體 雙語

Sample Image - imageButtons.gif

介绍

就像你所知道的,在 ASP.NET 中 ImageButton 无法显示为已经禁用。 为了解决这个问题,我编写了下面的代码。

使用这里控件,你可以轻松显示已经禁用 ImageButton 你可以指定四个不同的值 宋体 在这里控件中。

  • 宋体
  • DisableImageURL
  • MouseOverImageURL
  • MouseOutImageURL

代码


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 codeoverrideprotectedvoid 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>privatevoid 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 Eventsprivatevoid changeallfalse()
 {
 btnSave.Enabled = false;
 btnDelete.Enabled = false;
 btnNew.Enabled = false;
 btnCancel.Enabled = false;
 btnSearch.Enabled = false; 
 }
 privatevoid changeupdate()
 {
 if (kontrol.Text!="0" )
 {
 btnSave.Enabled = true;
 btnDelete.Enabled = true;
 btnNew.Enabled = true;
 btnCancel.Enabled = true;
 btnSearch.Enabled = true;
 kontrol.Text = "2";
 }
 }
 privatevoid changenew()
 {
 btnSave.Enabled = true;
 btnDelete.Enabled = false;
 btnNew.Enabled = false;
 btnCancel.Enabled = true;
 btnSearch.Enabled = false;
 kontrol.Text = "1";
 }
 privatevoid changenavigate()
 {
 btnSave.Enabled = false;
 btnDelete.Enabled = false;
 btnNew.Enabled = true;
 btnCancel.Enabled = true;
 btnSearch.Enabled = true;
 }
 privatevoid changedefault()
 {
 btnSave.Enabled = false;
 btnDelete.Enabled = false;
 btnNew.Enabled = true;
 btnCancel.Enabled = true;
 kontrol.Text = "0";
 btnSearch.Enabled = true;
 }
 #endregion#region ToolBarButton ClickEventsprivatevoid btnSave_Click(object sender, System.EventArgs e)
 {
 }
 privatevoid btnCancel_Click(object sender, System.EventArgs e)
 {
 changedefault();
 }
 privatevoid btnNew_Click(object sender, System.EventArgs e)
 {
 changenew();
 }
 privatevoid btnDelete_Click(object sender, System.EventArgs e)
 {
 }
 privatevoid btnSearch_Click(object sender, System.EventArgs e)
 {
 if (kontrol.Text=="2") { changedefault();return; }
 kontrol.Text = "0";
 btnCancel. Enabled = false;
 btnSave.Enabled = false;
 }
 #endregion }
}

相关文章